Convert from Image to Bitmap

F

Fritz Switzer

With two controls a PictureBox and another "PictureBox like" , Pic2, a
control from a dll, I'm stuck on cannot implicity convert
System.Drawing.Image to System.Drawing.Bitmap error.

How do I convert the following code so that the Pic2 can accept the Image
from the stream where it wants Picture property not and Image property.
Here is a snippet, I'm trying to avoid writing to disk.:

Image i = Pic1.Image;

MemoryStream ms = new MemoryStream();

i.Save(ms, ImageFormat.Jpeg); // need to save in jpeg for Pic2

//Read from MemoryStream into Byte array.

Byte[] bytBLOBData = new Byte[ms.Length];

ms.Position = 0;

ms.Read(bytBLOBData, 0, Convert.ToInt32(ms.Length));

Pic2.Picture = Image.FromStream(ms); // this is the line throwing the
"cannot convert System.Drawing.Image to System.Drawing.Bitmap


Thanks any help would be appreciated,
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Fritz,

Introduce an intermediate variable like thi:
ms.Read(bytBLOBData, 0, Convert.ToInt32(ms.Length));

Image img = Image.FromStream(ms);
Pic2.Picture = img;

And inspect the actual type of this "img" variable.
By the way, why is your assigment of one PictureBox's Image to another's is
so complicated?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE


Fritz Switzer said:
With two controls a PictureBox and another "PictureBox like" , Pic2, a
control from a dll, I'm stuck on cannot implicity convert
System.Drawing.Image to System.Drawing.Bitmap error.

How do I convert the following code so that the Pic2 can accept the Image
from the stream where it wants Picture property not and Image property.
Here is a snippet, I'm trying to avoid writing to disk.:

Image i = Pic1.Image;

MemoryStream ms = new MemoryStream();

i.Save(ms, ImageFormat.Jpeg); // need to save in jpeg for Pic2

//Read from MemoryStream into Byte array.

Byte[] bytBLOBData = new Byte[ms.Length];

ms.Position = 0;

ms.Read(bytBLOBData, 0, Convert.ToInt32(ms.Length));

Pic2.Picture = Image.FromStream(ms); // this is the line throwing the
"cannot convert System.Drawing.Image to System.Drawing.Bitmap


Thanks any help would be appreciated,
 

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