Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,, How to open image in C# and convert to binary and show it on the form??
Posted
Comments
Ashwani Gusain 21-Oct-13 0:29am    
in which format u want, asp.net or windows application
a7med ssss 21-Oct-13 2:55am    
windows application
monochrome image
Zoltán Zörgő 21-Oct-13 4:06am    
Just a note: an image file is always binary data (what else could it be?). Please try to formulate correctly.
a7med ssss 21-Oct-13 5:27am    
@Zoltán Zörgő ,, i know that, but i want choose monochrome image from my pc and convert it to 2d array binary of (0,1) and show the image from this array on form.
Zoltán Zörgő 21-Oct-13 5:33am    
Don't do that, you loose considerable amount of performance. See my answer.

hi try this

on select button click

C#
OpenFileDialog o = new OpenFileDialog();
o.ShowDialog();
path = o.FileName;
pictureBox1.ImageLocation = path;
txtImage.Text = path;


convert to binary
C#
byte[] b = ImageToByte(path);

showing on form
C#
pictureBox1.Image = path;
 
Share this answer
 
v2
Comments
a7med ssss 21-Oct-13 3:40am    
thx @Ashwani Gusain ,, but i want the image convert to 2d array Binary (width and height of image) after that, show the image on form from this array.
Ashwani Gusain 21-Oct-13 4:31am    
what u want really. U can acess pixel directaly through this code.
Try This code:-

OpenFileDialog ofdPic= new OpenFileDialog();
if (ofdPic.ShowDialog() == DialogResult.OK) {
	PicPath= ofdPic.FileName;
	Image Img = Image.FromFile(PicPath);
	pictureBox1.Image = Img;
}
 
Share this answer
 
You don't need to convert it to a 2D array, you can access the Pixels directly: http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx[^]. Well, this is not quite the fastest method by default, see this to improve performance: Work with bitmaps faster in C#[^]. But you can use other libraries too, to access low level image data[^]. If you want to do image processing, you have to consider OpenCV (EmguCV[^] for .net) in any case.
 
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