Domanda

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?

È stato utile?

Soluzione

I'm not sure about Crystal Reporting but to ReportViewer I'm able to pass parameters, those takes only string or string[] so you need to pass in one of these forms.

OR save your image as temporary file and just load it into pictureBox.

pictureBox1.Load("c:\\temp\\kitten.jpg");

OR follow this guide

http://morecoding.wordpress.com/2012/08/07/passing-mages-crystalreport-runtime/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top