error displaying an image in PictureBox

R

rocio

I have this segment of code to display an image in a PictureBox:

Private ms as MemoryStream

Public Function DisplayImage(byval bufBmp as Byte()) as Boolean
try
ms = new MemoyStream(bufBmp)
PictureBox1.Image = New Bitmap(ms)
PictureBox1.Update()
: :
catch ex as Exception
MsgBox(ex.toString)
end try

it crashes on the PictureBox1.Image = New Bitmap(ms) statement with the error:
System.ArgumentException: ArgumentException

any ideas why?
I checked that ms is defined, by inserting a line after defining ms to display its length in bytes.
 
A

Alex Feinman [MVP]

What's inside bufBmp? I assume that you are still struggling with VeoCamera and the buffer is a bitmap received from the camera preview or snapshot. If you take a look at the file I sent you earlier, you will notice that I manually prepend the bitmap header to the image. The header contents will depend on the bitmap format - I update it depending on the resolution selected in the StartPreview method. The header is prepopulated by some static data - http://www.alexfeinman.com/download.asp?doc=frame.hdr

I have this segment of code to display an image in a PictureBox:

Private ms as MemoryStream

Public Function DisplayImage(byval bufBmp as Byte()) as Boolean
try
ms = new MemoyStream(bufBmp)
PictureBox1.Image = New Bitmap(ms)
PictureBox1.Update()
: :
catch ex as Exception
MsgBox(ex.toString)
end try

it crashes on the PictureBox1.Image = New Bitmap(ms) statement with the error:
System.ArgumentException: ArgumentException

any ideas why?
I checked that ms is defined, by inserting a line after defining ms to display its length in bytes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top