Hi guys,
Another cool stuff, many guys, asking in MS forums, how load the image to picture box from the device directory. it's pretty easy, there have many ways.
1.loan image directly from the location
2. load the image from the memory stream.
So here code for you
1.
pictureBox.Image = new Bitmap (“Full.Path.To.Bitmpap.”);
2.
private void LoadImage(string filePath)
{
using (FileStream reader = new FileStream(filePath, FileMode.Open))
{
byte[] data = new byte[reader.Length];
reader.Read(data, 0, (int)reader.Length);
using (MemoryStream memory = new MemoryStream(data))
{
pictureBox1.Image = new Bitmap(memory);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
}
}
Thank you
Subscribe to:
Post Comments (Atom)
5 comments:
Hi, i have a question: in the first case, between the () you shoul type the relative path of the image?
Thanks
please specify about first example, the path should be relative, i am trying diferent versions of path and every time i get the error that path is incorrect during program run
hi there
This worked for me thanks.
hi and thanks by the post! but I get an error in the line code:
pictureBox1.Image = new Bitmap(memory);
the error is "OutOfMemoryException"
How to solve it?
I am running on Compact Framework 3.5
Post a Comment