Welcome Guest! You need to login or register to make posts.



Go to last post Go to first unread
Alex Kon  
#1 Posted : Friday, January 11, 2008 9:16:18 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Here is small code sample which demonstrates how to change palette of a bitmap.

Palette property of the Aurigma.GraphicsMill.Bitmap class is read-only so you cannot just assign new value to it. The only way is to manually replace values of the palette entries.

Lets assume that you have an indexed bitmap and new palette data (for example, in a raw byte array) which you get from some external sacral source. The method below will assign these values to the specified bitmap.

void ReplacePalette(Aurigma.GraphicsMill.Bitmap bmp, byte[] palette)
	if (bmp == null || bmp.IsEmpty)
		throw new ArgumentException("The image cannot be empty.");
	if (!bmp.IsIndexed)
		throw new ArgumentException("The image should be indexed.");
	if (palette.Length % 3 != 0)
		throw new ArgumentException("Wrong palette byte size.");

	int paletteSize = palette.Length / 3;
	int entriesToReplace = Math.Min(paletteSize, bmp.Palette.Count);
	for (int i = 0; i < entriesToReplace; i++)
		byte r = palette[3 * i + 0];
		byte g = palette[3 * i + 1];
		byte b = palette[3 * i + 2];

		bmp.Palette[i] = 
			Aurigma.GraphicsMill.RgbColor.FromRgb(r, g, b);

Note that this method changes only existing entries. You cannot change number of entries in the color map of the created bitmap (because it may cause some orphan pixels to appear). And if you really need to change number of entries - the only way is to create new bitmap with required color map capacity and copy data into it (I can provide you with code sample for that case too - feel free to post comments).

And another note: this sample changes color map independently from pixel data. It is a rather rare task, in most cases you need to convert image from one palette to another - and in such situations you should use Aurigma color conversion methods, which will change pixel data along with color map.

Edited by moderator Monday, May 28, 2012 8:45:43 PM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.