Click here to Skip to main content
15,745,005 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!!!
Updated 30-Dec-11 20:35pm
Sergey Alexandrovich Kryukov 30-Dec-11 11:02am    
Why this strange way.
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.
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:[^]
Share this answer
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
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![^],[^] (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[^].

Share this answer
Wendelius 30-Dec-11 15:58pm    
Very thorough, again :) 5+
Sergey Alexandrovich Kryukov 30-Dec-11 21:33pm    
Thank you, Mika.
thatraja 30-Dec-11 23:29pm    
Sergey Alexandrovich Kryukov 30-Dec-11 23:59pm    
Thank you, Raja.
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