In my database I have a table that contains an image column.
This column type is text
.
When saving images in a database that would convert to text.
My code is:
Image selectedImage = Image.FromFile(openFileDialog.FileName);
MemoryStream tmpStream = new MemoryStream();
selectedImage.Save(tmpStream, ImageFormat.Jpeg); // change to other format
tmpStream.Seek(0, SeekOrigin.Begin);
Byte[] BytesOfImage = tmpStream.ToArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < BytesOfImage.Length - 1; i++)
{
sb.Append(BytesOfImage[i] + ",");
}
sb.Append(BytesOfImage[BytesOfImage.Length - 1]);
sb.ToString(); // sb.ToString() ==> Save to sql server
And then convert the string to a photo, I use the following code:
String[] split = strImage.Split(',');
Byte[] bytes = new Byte[split.Length];
Byte b;
for (int i = 0; i < split.Length; i++)
{
Byte.TryParse(split[i], out b);
bytes[i] = b;
}
MemoryStream tmpStream = new MemoryStream();
tmpStream.Write(bytes, 0, bytes.Length);
tmpStream.Seek(0, SeekOrigin.Begin);
Image img = Image.FromStream(tmpStream);
Now I want in my report will display the image but the image path does not exist because the image is stored in the database!
How do I view the images?