Click here to Skip to main content
15,888,061 members
Please Sign up or sign in to vote.
2.11/5 (2 votes)
See more:
I have made a program which displays a bitmap image by using bitmap class.But my actual requirement is to display a bitmap image using binary reader and then convert it into grayscale...please help me out in this.
I just d'not want to use bitmap class,want to accomplish the task by using Binary Reader and after reading the Image using Binary Reader, i require it to be converted into GreyScale, now i hope i have clarified my question.Help!!!
Posted
Updated 30-Dec-11 20:35pm
v2
Comments
Sergey Alexandrovich Kryukov 30-Dec-11 11:02am    
Why this strange way.
--SA
Sergey Alexandrovich Kryukov 30-Dec-11 11:11am    
WPF or System.Drawing -- what do you want to use? If you know the answer, add a tag to the question.
--SA
Malik Azhar Awan 30-Dec-11 15:25pm    
hahahahah i have also same question means how to convert using binary reader........!!!

If you read a bitmap with a binary reader (i.e. as raw data bytes) and then try to convert it to grayscale manually, then you will have to read up on and implement Bitmap file format - probably a lot more than you need to do, in order to convert an image to greyscale.

There is a tutorial with code on how to do such conversion here: http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale[^]
 
Share this answer
 
Comments
Sridhar Patnayak 30-Dec-11 6:22am    
Good link -- my 5
Mariyah Malik 31-Dec-11 2:26am    
thanks,but still you are using bitmap class not binary reader...i have worked on this before,this was nice tutorial but not enough for my requirements.hope to see some good help on
"CONVERSION BY BINARY READER"
This is a bad approach, but many reasons. First of all, the two: 1) it's too difficult, unreliable and hard to maintain, 2) absolutely non needed.

Assuming you want to use System.Drawing, you need to do the following:
  • Use the class System.Drawing.Bitmap; read the bitmap from file using one of its constructors.
  • Create a target bitmap with the different pixel format (whatever you need, like 8 bits per pixel) and the same size.
  • Get access to source bitmap and target bitmaps using System.Drawing.Bitmap.LockBits; move data appropriately with the conversion of each bit you need.
  • PROFIT!


http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx[^],
http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[^] (find a code sample here).

Important! Don't even think about using GetPixel/SetPixel — it would be too slow.

WPF have its own approach. Look at System.Windows.Media.Imaging.WriteableBitmat, see http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx[^].

—SA
 
Share this answer
 
v3
Comments
Wendelius 30-Dec-11 15:58pm    
Very thorough, again :) 5+
Sergey Alexandrovich Kryukov 30-Dec-11 21:33pm    
Thank you, Mika.
--SA
thatraja 30-Dec-11 23:29pm    
5!
Sergey Alexandrovich Kryukov 30-Dec-11 23:59pm    
Thank you, Raja.
--SA
NandaKumer 30-Dec-11 23:58pm    
good one
 
Share this answer
 

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