Groups | Blog | Home
all groups > dotnet drawing api > may 2005 >

dotnet drawing api : Saving Grayscale image as real grayscale



bert
5/27/2005 12:00:00 AM
I want to save an image which I converted to grayscale as a real
grayscale image.


When I save the image and open it in photoshop, the mode is RGB
color/ 8bit.
I want the mode to be grayscale.

I've been searching for a solution for my problem for some time now
but I can't seem to find an answer.

Hopefully somebody can help me.
I know there are some .NET components around that I can use, but I
prefer to do it myself.

Morten Wennevik
5/27/2005 12:00:00 AM
Hi Bert,

There is no 8bpp GrayScale pixelformat, only a 16bpp one and I'm not sure you can use that either as I think all the 16bpp formats are broken.

--
Happy coding!
bert
5/27/2005 12:00:00 AM
Hi morten,

I know there is no grayscale pixelformat. The bitmap is a 8bpp format
wich is converted to grayscale using colormatrix.
I'm trying to find a way to save this RGB bitmap as grayscale.

The 16bppGrayscale pixalformat is indeed broken. It shouldn't be in
the framework sourcecode but somebody left it in :-(



On Fri, 27 May 2005 12:23:11 +0200, "Morten Wennevik"
[quoted text, click to view]
Morten Wennevik
5/27/2005 12:00:00 AM
Ah, now I get you.

If you have an 8bpp color bitmap to begin with. Simply convert the palette to grayscale.

ColorPalette pal = myBitmap.Palette;
for(int i = 0; i < pal.Entries.Length; i++)
{
Color c = pal.Entries[i];
int gray = (int)(c.R * 0.3086f + c.G * 0.6094f + c.B * 0.082f);
pal.Entries[i] = Color.FromArgb(255, gray, gray, gray);
}
myBitmap.Palette = pal;


[quoted text, click to view]



--
Happy coding!
AddThis Social Bookmark Button