ComputerForum.com ComputerForum.com  
Go Back   Computer Forum > Computer Software > General Software

Reply
 
LinkBack Thread Tools Display Modes
Old 07-13-2005, 07:04 PM   #1 (permalink)
New Member
 
Join Date: Feb 2005
Posts: 14
Default Image Binarization

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);
sarabjit is offline   Reply With Quote


Old 07-13-2005, 08:25 PM   #2 (permalink)
VIP Member
 
Lorand's Avatar
 
Join Date: Dec 2003
Location: Bucharest
Age: 42
Posts: 3,042
Default

Try this method: http://www.bobpowell.net/onebit.htm
Lorand is offline   Reply With Quote
Old 07-14-2005, 03:49 PM   #3 (permalink)
New Member
 
Join Date: Feb 2005
Posts: 14
Default

Thanks...
The article helped me find a solution...
sarabjit is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT +1. The time now is 09:51 PM.


Powered by: vBulletin Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Copyright © 2002-2008 Computer Forum and Web Design Forum