Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have an image of byte[] format in database . I retrieve that image using execute scalar() method.how to display that image in asp.net image control
Posted

See this article[^] :)

-KR
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Feb-14 2:28am    
Right, a 5.
—SA
Krunal Rohit 18-Feb-14 3:56am    
Thanks SA :)

-KR
public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}


for more detail see link below
C# Image to Byte Array and Byte Array to Image Converter Class[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Feb-14 2:27am    
Correct, a 5.
—SA
Try something like this

using (SqlConnection conn = ...)
{
conn.Open();

using (SqlCommand cmd = new SqlCommand("SELECT Picture FROM <tablename> WHERE ...", conn)
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
byte[] picData= reader["Picture"] as byte[] ?? null;

if (picData!= null)
{
using (MemoryStream ms = new MemoryStream(picData))
{
// Load the image from the memory stream. How you do it depends
// on whether you're using Windows Forms or WPF.
// For Windows Forms you could write:
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
}
}
}
}
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Feb-14 2:29am    
ASP.NET...

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