Converting Image files in InfoPath to gifs once submitted

By David Fekke
January 17th, 2011

I have been developing a lot of windows workflows and web services in .NET recently. I came across a need to convert a WMF file (Windows Meta File) into a gif file. SQL Server Reporting Services can not display WMF files.

.NET 2.0 can convert and resize images natively. Here is how I converted the WMF files. First I added the following using statements;

using System.Drawing;

using System.Drawing.Imaging;

InfoPath saves images as Base64 strings, and .NET treats this as a byte array. So I had to convert the WMF byte array to a gif byte array.

byte[] imageByteArray = DiagramImage;

MemoryStream inStream = new MemoryStream(imageByteArray);

StreamReader myStreamReader = new StreamReader(inStream);

Image myImage = Image.FromStream(inStream);

Bitmap myBitmap = new Bitmap(myImage);

Graphics myGraphics = Graphics.FromImage(myBitmap);

//Keep background white.


myGraphics.DrawImage(myImage, 0, 0, myImage.Width, myImage.Height);

MemoryStream outStream = new MemoryStream();

myBitmap.Save(outStream, ImageFormat.Gif);

byte[] gifByteArray = outStream.GetBuffer();
← Previous Page  Next Page →