Change bitmap palette for an image

1k Views Asked by At

I have a TIFF image for which I wish to change the BitmapPalette for a specific frame of the image.

I have the following code:

var width = image.Frames[0].PixelWidth;
var height = image.Frames[0].PixelHeight; 
var dpiX = image.Frames[0].DpiX;
var dpiY = image.Frames[0].DpiY;

var listOfColors = new List<System.Windows.Media.Color>();
for (int i = 0; i < 256; i++)
{
      listOfColors.Add(System.Windows.Media.Color.FromRgb((byte)i, (byte)i, (byte)i));
}
var pallet = new BitmapPalette(listOfColors);

newImage = new WriteableBitmap(width, height, dpiX, dpiY, PixelFormats.Indexed8, pallet );

This returns an white image: why? What am I doing wrong here?

Also, if you have any information on how can I parse a GGR file into a BitmapPalette, that would be nice.

1

There are 1 best solutions below

0
Mojtaba On

You only filled in the bitmappalette(pallete), not the writeablebitmap inage (newImage).

The bitmap palette plays the role of a look-up table for your writeablebitmap image.

You should fill in your writeablebitmap image (newImage) with indexes to the bitmappalette(palette).