[GIS] Can custom map tiles be properly rendered via ArcObjects within ArcMap AddIn

arcgis-10.1arcobjectscnet

Within ArcObjects for ArcGIS 10.1, we are attempting to render pre-generated map tiles as a
basemap (group) layer. The tiles themselves are of the typical web mercator aux. spherical tiling scheme.

Under ArcMap 10.1 the tiles do not render properly:

incorrect rendering result

and the ArcMap 10.1 UI is displaying the following drawing error: "Missing raster band wavelength properties"

[Expected] rendering result under ArcMap 10.0:

enter image description here

While this is related to Can custom map tiles be consumed via ArcObjects within my ArcGIS 10 Desktop AddIn? that was a holistic approach question. Here I am specifically asking how to properly render the tiles in ArcMap 10.1.

We successfully accomplished the layer adding/rendering within 10.0 via the following code:

_tileLayer = new MyCustomTileLayer();    // implements ILayer among others..
_coverageBasemapLayer = new BasemapLayerClass();
_coverageGroupLayer = _coverageBasemapLayer as IGroupLayer;

// add the layer to the map
IMap map = ArcMap.Document.FocusMap;
map.AddLayer((ILayer)_coverageBasemapLayer);

...

// wire the AfterDraw Event
IActiveViewEvents_Event avEvent = ArcMap.Document.FocusMap as IActiveViewEvents_Event;
avEvent.AfterDraw += new IActiveViewEvents_AfterDrawEventHandler(avEvent_AfterDraw);

private void avEvent_AfterDraw(IDisplay Display, esriViewDrawPhase phase) {
    // force re-draw
    _tileLayer.Draw(esriDrawPhase.esriDPGeography, Display, null);
}

...

// effectively, within _tileLayer.Draw() here...
IRasterLayer rl = new RasterLayerClass();
// 'file' is the full path to the map tile PNG on the local file system, downloaded
// and/or cached
rl.CreateFromFilePath(file);

_coverageGroupLayer.Add(rl);

Presumably many things have changed within the renderer for 10.1.

However can anyone provide insight into the ArcObjects changes required?

Specifically, how can we [properly] accomplish this within ArcObjects under 10.1?

Best Answer

In 10.1 the StretchType for rasters seems to have changed from esriRasterStretch_NONE to "Percent Clip" giving color problems with 24 and 32 bits tiles.

I have resolved it with the following code:

var image = new Bitmap(file, true);
var format = image.PixelFormat;
if (format == PixelFormat.Format24bppRgb || format == PixelFormat.Format32bppArgb || format == PixelFormat.Format32bppRgb)
{
    var rasterRGBRenderer = new RasterRGBRendererClass();
    ((IRasterStretch2rasterRGBRenderer).StretchType =
               esriRasterStretchTypesEnum.esriRasterStretch_NONE;
    rl.Renderer = rasterRGBRenderer;
}
Related Question