Click here to Skip to main content
15,914,795 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello,

Can anyone tell me how to convert Byte array to image format.....i have stored image in byte array to database..now i want to retrieve that image

Thank you
Posted
Comments
[no name] 7-Jul-15 10:24am    
Did you do anything like a simple google search before asking? You should have got thousands to results if you had....

Hello ,
You can convert the image from bytearray to its original form by this function
public Image GetDataToImage(byte[] pData)
       {
           try
           {
               ImageConverter imgConverter = new ImageConverter();
               return imgConverter.ConvertFrom(pData) as Image;
           }
           catch (Exception ex)
           {
               return null;
           }
       }

Now pass the byte[] array in the function , which is stored in Database and you will get Image .

Thanks
 
Share this answer
 
Comments
Member 11148509 9-Jul-15 2:28am    
have tried this but could not get the image ...
Animesh Datta 9-Jul-15 3:40am    
what are you getting ?
Member 11148509 9-Jul-15 3:42am    
Not getting anything ....no image in radbinary image
Member 11148509 9-Jul-15 3:49am    
actually in database its storing in hex format i think i need to convert to hex...instead of byte array..
this is how its storing ....
0x424D769C000000000000360000002800000064......
Animesh Datta 9-Jul-15 4:02am    
first let me know What datatype are you using to store the image and where you want to show the retrieved image ? in picturebox ?
See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] - it explains teh way to get the image, and explains how to store it, just in case you might have got that wrong! ;laugh:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900