469,579 Members | 1,181 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Convert from Image to Bitmap

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,
--
Fritz
Nov 15 '05 #1
1 49354
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" <fr***********@comcast.net> wrote in message
news:e2*************@TK2MSFTNGP11.phx.gbl... 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,
--
Fritz


Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by News VS.NET \( MS ILM \) | last post: by
5 posts views Thread by Socrates | last post: by
5 posts views Thread by stef | last post: by
1 post views Thread by =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post: by
4 posts views Thread by alarock | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.