472,353 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 50006
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: News VS.NET \( MS ILM \) | last post by:
Hello I have the following: Dim myBitmap As New Bitmap(600, 500) Q: How to convert a Bitmap to a Buffer() of Bytes
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on...
5
by: Socrates | last post by:
I am interested in developing an online utility that will enable users to copy and past any image (or upload any image on the internet) to the...
5
by: stef | last post by:
hello I can find all kind of procedures to convert an array to a bitmap (wxPython, PIL), but I can't find the reverse, either - convert a...
1
by: gnkt4ujt2002 | last post by:
how to convert image into hex format in vs.net 2003 ....bcoz i hav 2 send image on mobile using sms tgate way.. i hav a clickatell sms gate way...
2
by: Peter Oliphant | last post by:
The Image class allows loading a bitmap from a graphic file. So far I've gotten it to work with JPG and BMP files. What other graphic file...
1
by: =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post by:
I'm using OpenGL in Visual Basic .net 2005 and i need to use the following function glBitmap(width as integer,height as integer, xorig as single,...
4
by: alarock | last post by:
hi, I have performed some drawing using Vector image,DrawRectangle etc... and then i converted to raster Image(bitmap) i found in the ...
3
by: surajhs | last post by:
hi, I am working on java applet, i created a interface to view image in panel on jlist selected image item which is in local machine path, Now i...
1
by: surajhs | last post by:
i need to convert image to binary data and create xml file in applet, Please send samples links
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.