|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Convert byte[] into image using ASP.Net I was able to convert my images to Byte[] but not able to get it convet it into the Byte[] to image, i have number of images stored in my database and they are in the JPG format. Is there any best way to convert these pictures from Byte[] to Image. I've got the image in the var Image: byte[] Image; I have tried some code for this in ASP.net but when i execute this code it gives me list of error messages. Regards |
#2
| |||
| |||
Re: Convert byte[] into image using ASP.Net To access to the image you need to create a MemoryStream from the byte array and then call Image.FromStream, Convert Image to byte[] array: Code: public byte[] imageToByteArray(System.Drawing.Image imageIn) { MemoryStream img = new MemoryStream(); imageIn.Save(img,System.Drawing.Imaging.ImageFormat.Gif); return img.ToArray(); } Code: Image MemoSt; DataPhoto = new Byte[File.ContentLength]; MemoSt=Image.FromStream(DataPhoto); Code: public Image byteArrayToImage(byte[] byteArrayIn) { MemoryStream img = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(img); return returnImage; } |
#3
| |||
| |||
Re: Convert byte[] into image using ASP.Net If you have not properly coded your image flushing then data is not being recognized as an image format. and to check that you may try using a System.Drawing.Bitmap method instead of an Image, to see if that will work you just need to pass 'data' into the constructor (Dim b As New Bitmap(ms) ),Even if doing this changes doesn't work, you should need to post your code that converts from a file to bytes to see if the problem lies there. and this problem might be related to the improper flushing of your images. |
#4
| |||
| |||
Re: Convert byte[] into image using ASP.Net While searching on the internet i read in one blog that you need to convert a byte array to back to an image so that it can be displayed in a PictureBox control, you can use the following function: Code: public Image ByteArrayToImage(byte[] data) { MemoryStream bipimag = new MemoryStream(data); Image imag = new Bitmap(bipimag); return imag; } pictureBox2.Image = ByteArrayToImage(data); |
![]() |
|
Tags: asp dot net, byte array, image conversion, programming |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Convert 2D image into 3D image using Silverlight 4 | Thenral | Windows Software | 5 | 18-04-2011 10:45 AM |
Can I convert MBM image to JPG...Is this possible? | Bon-hwa | Operating Systems | 4 | 11-11-2010 12:34 AM |
Convert image byte [] using java | Miles Runner | Software Development | 5 | 02-02-2010 03:38 AM |
Convert Vmware Image to Virtualbox Image | rashmi_ay | Windows Software | 5 | 23-12-2009 02:56 PM |
help! How to convert bootable diskette image and bootable CD image to bootable flash/usb stick? | Vicious | Windows XP Support | 4 | 20-05-2009 01:32 PM |