Possible to extract Embedded image to a file?

Go To StackoverFlow.com

9

Given a SSRS report definition file with an embedded image in it, just wondering if its possible to extract that image XML to recreate the original image file.

e.g. :

inside the rdlc file, you might see xml like this :

<EmbeddedImage Name="tick">
  <MIMEType>image/bmp</MIMEType>
  <ImageData>Qk1mAwAAAAAAADYAAAAoAAAAEAAAABEAAAABABgA ... <<REST OF IMAGE HERE>>
  </ImageData>
</EmbeddedImage>

Is it possible to take the ImageData, and transform form it in some way to re-create the original image bitmap byte stream ?

(This might be useful in cases such as when you've lost the original image file on which the embedded image was based.)

2012-04-04 03:46
by Moe Sisko


16

Two approaches are detailed in this blog post:

  1. Copy the encoded image from one report to another if you need to reuse it there.
  2. Export a copy of the report to Excel and copy the image from the spreadsheet.

Or if you need access to the image more directly, I found this utility that will parse the XML and load and export the images. Looks like source code is available.

2012-04-04 13:46
by Jamie F
thanks, the utility works well. A slight change was required to make it also work for rdlc files (including the *.rdlc filespec in the file open dialog) - Moe Sisko 2012-04-05 01:06
Excel export worked great - JustJohn 2018-05-01 19:13


6

I have created a small Power Shell script to solve this problem:

$ErrorActionPreference = 'Stop';
Get-ChildItem -Filter '*.rdl' | ForEach {
    $reportFile = $_;
    Write-Host $reportFile;
    $report = [xml](Get-Content $reportFile);
    $report.Report.EmbeddedImages.EmbeddedImage | Foreach {
        $imagexml = $_;
        $imageextension = $imagexml.MIMEType.Split('/')[1];
        $filename = $imagexml.Name + '.' + $imageextension;
        Write-Host '->' $filename;
        $imageContent =  [System.Convert]::FromBase64String($imagexml.ImageData);
        Set-Content -Path $filename -Encoding Byte -Value $imageContent;
    }
}

https://gist.github.com/Fabian-Schmidt/71746e8e1dbdf9db9278

This script extracts all images from all reports in the current folder.

2016-03-29 22:12
by Fabian
Lifesaver - thanks - CamM 2017-07-27 23:58


1

I just needed to do this and realised that it is possible to cut and paste the embedded image, even though it is not possible to copy and paste.

2014-05-30 15:17
by csharpsql
Ads