Image Binarization

Status
Not open for further replies.

sarabjit

Solid State Member
Messages
11
I load an image, convert it to bitmapData using the 24bppRGB pixel format, binarize it using a simple routine (shown below) and save it using the Image.Save() method. The image saved however is still 24bppRGB - although all colours have the same value, either 0 or 255 - and shows up as an RGB image in Photoshop.

Any ideas on how I can change it to binary, ie a 1bpp format?

Code:
------

Bitmap bMap=new Bitmap (iMage);
BitmapData bData = bMap.LockBits(new Rectangle(0, 0, bMap.Width, bMap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
System.IntPtr Scan0 = bData.Scan0;
int iStride=bData.Stride;
int iht=bMap.Height;
int iwd=bMap.Width;
int iPix=new int[iht][];
unsafe
{
byte *p = (byte*)(void*)Scan0;
int nOffset = iStride-iwd*3;
for(int y=0;y<iht;++y)
{
iPix[y]=new int[iwd];
for(int x=0;x<iwd;++x)
{
if (conditionA) p[0]=p[1]=p[2]=0;
else p[0]=p[1]=p[2]=255;
p += 3;
}
p += nOffset;
}
}
bMap.UnlockBits(bData);

bMap.Save(fileName);
 
Status
Not open for further replies.
Back
Top Bottom