views:

776

answers:

4

I have a requirement to be be able to embed scanned tiff images into some SSRS reports.

When I design a report in VS2005 and add an image control the tiff image displays perfectly however when I build it. I get the warning :

Warning 2 [rsInvalidMIMEType] The value of the MIMEType property for the image ‘image1’ is “image/tiff”, which is not a valid MIMEType. c:\SSRSStuff\TestReport.rdl 0 0

and instead of an image i get the little red x.

Has anybody overcome this issue?

+2  A: 

Assuming you're delivering the image file via IIS, use an ASP.NET page to change image formats and mime type to something that you can use.

Response.ContentType = "image/png";
Response.Clear();
using (Bitmap bmp = new Bitmap(tifFilepath))
  bmp.Save(Response.OutputStream, ImageFormat.Png);
Response.End();
Peter Wone
Didn't complile for me. This does though http://stackoverflow.com/questions/126584/displaying-tiff-files-in-ssrs-reports#132873 S
John Nolan
+1 for idea though
John Nolan
It was a sketch only, not clipped from real code. May I suggest you use PNG rather than JPEG unless you are processing photographic images? Tiff is a non-loss format; this is why I selected another non-loss format.
Peter Wone
In the code from which the idea came I compose a tile of a specified size from smaller aerial photo tiles. Then I draw annotations on it and deliver the finished image. The code is far too involve to clearly illustrate the principle.
Peter Wone
I got some weird gdi error with png. Jpeg will suit for this task.
John Nolan
Oh yes, I forgot about that. That's a bug in conversion to a quantised palette, it doesn't get initialised correctly. As I recall you can dodge this by converting to BMP and then to PNG.
Peter Wone
A: 

Thanks Peter your code didn't compile but the idea was sound.

Here is my attempt that works for me.

protected void Page_Load(object sender, EventArgs e)
{
    Response.ContentType = "image/jpeg";
    Response.Clear();        
    Bitmap bmp = new Bitmap(tifFileLocation);
    bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
    Response.End();

}
John Nolan
A: 

I have been goggling fora solution on how to display a TIFF image in a SSRS report but I couldn't find any and since SSRS doesn's support TIFF, I thought converting the TIFF to one of the suppported format will do the trick. And it did. I don't know if there are similar implementation like this out there, but I am just posting so others could benefit as well. Note this only applies if you have a TIFF image saved on database.

Public Shared Function ToImage(ByVal imageBytes As Byte()) As Byte()
    Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(imageBytes)
    Dim os As System.IO.MemoryStream = New System.IO.MemoryStream()
    Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(ms)

    img.Save(os, System.Drawing.Imaging.ImageFormat.Jpeg)

    Return os.ToArray()
End Function

Here’s how you can use the code: 1. In the Report Properties, Select Refereneces, click add and browse System.Drawing, Version=2.0.0.0 2. Select the Code Property, Copy paste the function above 3. Click Ok 4. Drop an Image control from the toolbox 4.1. Right-Click the image and select Image Properties 4.2. Set the Image Source to Database 4.3. In the Use this field, Click expression and paste the code below =Code.ToImage(Fields!FormImage.Value)
4.4. Set the appropriate Mime to Jpeg

Regards, Fulbert

Fulbert Fadri
A: 

What if TIFF file is a multipage image file. Converting it to JPEG or PNG truncates everything but the first page. :(

Ivan