-
March 24th, 2009, 11:02 AM
#1
Convert String to image
Hi , i want to save the image from the database to an physical location like C:\one.JPG. the datatype of the column in the table is Image. i tried with working with MemoryStream. but i am not suceed. i am getting "Parameter not valid" when converting the stream to image "Image.fromStream(ms,true)".
DataView dv = new DataView(ds.Tables[0], null, null, DataViewRowState.CurrentRows);
byte[] imageData =(Bytes) dv[0][3];
Image newImage;
//Read image data into a memory stream
using (MemoryStream ms = new MemoryStream(imageData, 0, imageData.Length))
{
ms.Write(imageData, 0, imageData.Length);
//Set image variable value using memory stream.
newImage = Image.FromStream(ms, true);
}
-
March 24th, 2009, 11:08 AM
#2
Re: Convert String to image
Hi,
Are you sure that you have the image data in "imageData"? Have you tried stepping through the application with the debugger?
-
March 25th, 2009, 03:05 AM
#3
Re: Convert String to image
I would try to call ms.Seek(0) before constructing the image. And are you sure that the raw data is in proper format? I think (I'm not able to prove it now) that it must be a BMP.
Also, keep in mind this statement from MSDN: "You must keep the stream open for the lifetime of the Image."
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|