Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi!
i want to create an app in c# windows which takes every pixel of an image(black and white) check that pixel if pixel is white,delete it if the pixel is black then leave at the end it saves the image as a bitmap. how is it possible?
Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 12-Feb-12 0:32am    
What is the question? Is it possible or not? The answer is "Yes, of course".
Is the case closed?
--SA
saifullahiit 12-Feb-12 0:36am    
i want to know how is it possible
Sergey Alexandrovich Kryukov 12-Feb-12 0:32am    
By the way, you did not tell us what library do you use. System.Drawing? WPF? Anything else?
--SA
saifullahiit 12-Feb-12 0:36am    
system.drawing
Sergey Alexandrovich Kryukov 12-Feb-12 0:33am    
What is "delete pixel"? :-)
--SA

1 solution

First of all, don't use GetPixel or SetPixel. This would be prohibitively slow, unless you want to retouch just a few pixels.

You need to use one of the System.Drawing.Bitmap.LockBits methods, please see:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^],
see the code sample here: http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[^].

What you do is: get raw byte representation of bitmap data and modify the bytes directly. The layout of the bytes and bits in this data and interpretation of the data in the bit color and (transparency, it it is applicable) depends on pixel format; please see System.Drawing.Imaging.PixelFormat, http://msdn.microsoft.com/en-us/library/3z132tat.aspx[^].

You can save the bitmap using one of the System.Drawing.Bitmap.Save methods.

This is a pretty good short article explaining how it works: http://www.bobpowell.net/lockingbits.htm[^].

Please see my comments to the question about "delete pixel"; there is no such thing. You can only modify pixel properties such as color and transparency where transparency is supported by the pixel format you use.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900