Converting Image files in InfoPath to gifs once submitted

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.Clear(Color.White);
myGraphics.DrawImage(myImage, 0, 0, myImage.Width, myImage.Height);
MemoryStream outStream = new MemoryStream();
myBitmap.Save(outStream, ImageFormat.Gif);
byte[] gifByteArray = outStream.GetBuffer();

Comments
todd sharp's Gravatar It would be really cool if you could show how to do this with CF .NET integration. Any chance you could do that?
# Posted By todd sharp | 2/12/08 8:56 AM
Karl's Gravatar Would you like to publish the complete list of your windows workflows.
# Posted By Karl | 6/11/08 10:01 AM
David Fekke's Gravatar Karl,

Unfortunately I can not because the rest of my work flows are not my intellectual property anymore.

Sorry,
David.
# Posted By David Fekke | 6/11/08 10:18 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.6.001.