473,324 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 50368
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 the local filesystem. What I want to do is use a...
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 online utility, which will then convert the image to...
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 bitmap to an array or - read a bitmap file to an...
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 formats are supported in this way? Is this fixed based...
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, yorig as single, xmove as single, ymove as...
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 zoomed raster image(bitmap) the outer...
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 need to convert image to xml and along with 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
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.