BigEd781
February 23rd, 2009, 05:26 PM
I have an image which is in the format of 32bppArgb. Now, this image is greyscale, so for every pixel, r = g = b, it is simply the brightness that varies. I would like to false color some of the pixels that are over-saturated (brightness > someConstant). I would like to use the Bitmap's Palette property, but to do so I need to have an indexed image.
So, I try to convert my image to 8bppIndexed. The problem is that the conversion routine does not know that the image is in greyscale, so every pixel gets set to pure black (i.e., no color, so every pixel is converted to the same thing in 8-bit land).
Does anyone know how to convert this image to 8bppIndexed without losing the brightness? I should note that I cannot loop through each pixel and check for myself. The user will be utilizing a TrackBar to change the overall intensity of the image. I cannot scan the entire image for every tick of the TrackBar, so a solution which uses the Palette property would be optimal.
BTW, if you guys know a better way to do this that is just as good.
EDIT:
Solved this by using the ImageAttributes class:
List<ColorMap> maps = new List<ColorMap>();
for (int i = 30; i < 256; ++i)
{
ColorMap map = new ColorMap();
map.OldColor = Color.FromArgb(255, i, i, i);
map.NewColor = Color.FromArgb(i, Color.Red);
maps.Add(map);
}
mAttrs.SetRemapTable(maps.ToArray());
So, I try to convert my image to 8bppIndexed. The problem is that the conversion routine does not know that the image is in greyscale, so every pixel gets set to pure black (i.e., no color, so every pixel is converted to the same thing in 8-bit land).
Does anyone know how to convert this image to 8bppIndexed without losing the brightness? I should note that I cannot loop through each pixel and check for myself. The user will be utilizing a TrackBar to change the overall intensity of the image. I cannot scan the entire image for every tick of the TrackBar, so a solution which uses the Palette property would be optimal.
BTW, if you guys know a better way to do this that is just as good.
EDIT:
Solved this by using the ImageAttributes class:
List<ColorMap> maps = new List<ColorMap>();
for (int i = 30; i < 256; ++i)
{
ColorMap map = new ColorMap();
map.OldColor = Color.FromArgb(255, i, i, i);
map.NewColor = Color.FromArgb(i, Color.Red);
maps.Add(map);
}
mAttrs.SetRemapTable(maps.ToArray());