Reputation: 459
I have no idea how to read an image in as a binary image. I have being using the following lines however it keeps reading in null.
FileStream inf = new FileStream(name.ToString(), FileMode.OpenOrCreate, FileAccess.ReadWrite);
BinaryReader data = new BinaryReader(inf);
Can anyone help?
Upvotes: 1
Views: 4381
Reputation: 240
It really depends on what you want to do. For example, if you want to read in a .bmp file and display it in a PictureBox, you can do something like the following:
(assumes there's a PictureBox named pictureBox1)
Stream bmpStream = null;
var ofd1 = new OpenFileDialog();
if(ofd1.ShowDialog()==DialogResult.OK)
{
try
{
bmpStream = ofd1.OpenFile();
if(bmpStream != null)
{
using (bmpStream)
{
pictureBox1.Image = new Bitmap(bmpStream);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: could not read file. " + ex.Message);
}
}
Upvotes: 1
Reputation: 11
why don't you take a look on this topic How to open image in C# and convert to binary,it seems to be like what you're asking for, but for image in black and white, however there are some methods that can help you. I hope you find this helpful or at least that lead you in the right direction.
Regards
Upvotes: 0