How to export transparent images from IMapServer2

Discussion created by disyednsubscription on Jun 25, 2013

I am trying to export image tiles from ArcMap to be used as overlays in my application. I utilize IMapServer.ExportMapImage for this purpose. It works just fine with the exception of the layers with Opacity/Transparency setting. The generated tiles are all opaque regardless of the layers opacity settings.

It is stated in the API Reference that:

[INDENT]Optimized MapServices add support for the image type PNG32 which allows the use of an alpha band (in addition to RGB bands) to support pixel level transparency. When using the PNG32 format, transparency set on layers in the map gets carried over to the output image.  This means that the client application does not need to set any client side transparency when draping the service on top of another map service. Use the ServiceConfigurationInfo property set to find out whether a map service supports PNG32.[/INDENT]

Does anybody here have any idea to what I am doing wrong here?

mapServer = new MapServerClass();
mapInfo = mapServer.GetServerInfo(mapServer.get_MapName(0));
mapDesc = mapInfo.DefaultMapDescription; 

ImageType imgType = new ImageType();
imgType.Format = esriImageFormat.esriImagePNG32;
imgType.ReturnType = esriImageReturnType.esriImageReturnMimeData;

IImageDisplay2 imgDisp = new ImageDisplay() as IImageDisplay2;
imgDisp.DeviceResolution = EXPORT_DPI;
imgDisp.Height = EDGE_SIZE;
imgDisp.Width = EDGE_SIZE;
imgDisp.TransparentColor = mapInfo.BackgroundColor;            

ImageDescription imgDesc = new ImageDescription();
imgDesc.Display = imgDisp as IImageDisplay;
imgDesc.Type = imgType;

mapDesc .MapArea = createMapArea(...);
mapDescription.TransparentColor = mapInfo.BackgroundColor;   
IMapImage mapImg = mapServer.ExportMapImage(mapDescription, imageDescription);

using (BinaryWriter writer = new BinaryWriter(File.Open(filePath, FileMode.Create)))

Best regards and thanks in advance
Yashar Moradi