English 中文(简体)
在SSRS报告中显示Tiff文件
原标题:
  • 时间:2008-09-24 11:28:44
  •  标签:

我有一个要求,能够将扫描的tiff图像嵌入到一些SSRS报告中。

当我在VS2005中设计报表并添加图像控件时,tiff图像在构建它时会完美显示。我收到警告:

警告2[rsInvalidMIMEType]图像“image1”的MIMEType属性的值为“image/tiff”,这不是有效的MIMETtype。c: SSRSStuffTestReport.rdl 0 0

我得到的不是图像,而是红色的小x。

有人克服了这个问题吗?

最佳回答

假设您通过IIS传递图像文件,请使用ASP.NET页面将图像格式和mime类型更改为可以使用的类型。

Response.ContentType = "image/png";
Response.Clear();
using (Bitmap bmp = new Bitmap(tifFilepath))
  bmp.Save(Response.OutputStream, ImageFormat.Png);
Response.End();
问题回答

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

谢谢Peter您的代码没有编译,但想法是正确的。

这是我的尝试,对我有效。

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();

}




相关问题