I can't seem to figure out how to load a pictureBox image from a bitmap in memory. Is it possible or do I have to create temp file for the bitmap?
Load Picturebox Image From Memory?
Asked Answered
Possible duplicate: stackoverflow.com/questions/743549 –
Hesiod
How do you have the bitmap in memory? –
Cestus
It is the opposite, loading the image from a file, that is unusual. Use the Bitmap class. –
Eros
What format is the image in memory?
If you have an actual Bitmap object, just assign it to the PictureBox, as suggested by dtb:
pictureBox.Image = bitmap;
If you have the image as a series of bytes held in a stream, you'll need to load the image from the stream:
var image = Image.FromStream(stream);
pictureBox.Image = image;
If you instead have a windows GDI handle to the bitmap, use
var image = Image.FromHbitmap(handle);
pictureBox.Image = image;
Essentially, it's hard to answer your question with more than suggestions when you haven't told us what format the Bitmap you have is held in.
I have received
System.ArgumentException: Parameter is not valid.
exception when i tried to load image from stream. –
Ireland @BalagurunathanMarimuthu I suggest posting your own question to get assistance with your particular context; it's difficult to assist with so little information. –
Zacharyzacherie
You can create a Bitmap from a MemoryStream:
pictureBox.Image = new Bitmap(new MemoryStream(byteArray));
at what point is it safe to explicitly Dispose of the MemoryStream ? Would : using(var ms = new MemorySteam(byteArray)){ pictureBox.Image = new Bitmap(ms) }; be safe ? –
Agenesis
@MoeSisko: You don't really need to dispose a MemoryStream; they don't have unmanaged resoruces. (just a
byte[]
) But, yes; that should be fine. –
Cestus parameter missing here
Dim picture As Byte() = GetBytes(ListView2.Items(index).SubItems(8).Text) Dim converter As New ImageConverter() PictureBox1.Image = DirectCast(converter.ConvertFrom(picture), Image)
–
Unchain pictureBox.Image = bitmap;
parameter missing here
Dim picture As Byte() = GetBytes(ListView2.Items(index).SubItems(8).Text) Dim converter As New ImageConverter() PictureBox1.Image = DirectCast(converter.ConvertFrom(picture), Image)
–
Unchain © 2022 - 2024 — McMap. All rights reserved.