Reputation: 1
I have a wired probly. I recieve pixel data from a web control (Awesomium).
I want to display the bipmap in a PictureBox.
using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(viewPortX, viewPortY, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
BitmapSurface bmpSurface = (BitmapSurface)htmlHolder.Surface;
bmpSurface.CopyTo(bmpData.Scan0, bmpSurface.RowSpan, 4, false, false);
bmp.UnlockBits(bmpData);
bmp.Save("result.jpg", ImageFormat.Jpeg);
pictureBox.Load(result.jpg);
}
This works fine. The bitmap is diaplayed. If I change
bmp.Save("result.jpg", ImageFormat.Jpeg);
pictureBox.Load(result.jpg);
to
pictureBox.Image = bmp;
then the eror image is shown in the PictureBox.
Any idea what's is wrong?
Greetings
Clemens Hoffmann
Upvotes: 0
Views: 1185
Reputation: 838
because you destroy bmp object before it get's loaded into picturebox. using statement dispose image created within it's range.
Upvotes: 1