I have a georeferenced IRasterLayer which is displaying data from a PPM file with no alpha channel. I am trying to specify a color which should be treated as transparent. In ArcMap it is possible to set a specific color to be transparent, but I have yet to find a working C++ example for ArcObjects 10.x .NET.
I am using the C++ COM interface and have been trying to achieve this by creating a RasterRGBRenderer as per this post. The claimed-working VB.NET sample passes an array of doubles into IRasterStretch.BackgroundValues which is not compatible with the documented 10.1 interface.
Unfortunately documentation in this area is poor, and these samples are very dated. The documentation does not even specify what type of COM VARIANT is needed when VARIANTS are expected.
Please advise how to specify background transparency using C++ in ArcObjects 10.x .NET
As a test I have attempted to set the BackgroundValue white to display as red using the following,
this did not work (This does work on a test PNG with a white background, but not my PPM file):
esri::IRasterRGBRenderer2Ptr rgbRenderer; rgbRenderer.CreateInstance(__uuidof(esri::RasterRGBRenderer)); IRasterRendererPtr rasterRenderer(rgbRenderer); rasterRenderer->Raster = rasterLayer->Raster; hr = rasterLayer->putref_Renderer(rasterRenderer); IRgbColorPtr backgroundColor; backgroundColor.CreateInstance(__uuidof(esri::RgbColor)); backgroundColor->put_RGB(RGB(255, 0, 0)); // Bright red for testing CComSafeArray<double> backgroundValue; backgroundValue.Create(3); backgroundValue.SetAt(0, 255.0); backgroundValue.SetAt(1, 255.0); backgroundValue.SetAt(2, 255.0); CComVariant varBackgroundValue(backgroundValue); IRasterStretch2Ptr stretch(rasterRenderer); hr = stretch->put_Background(VARIANT_TRUE); hr = stretch->putref_BackgroundColor(backgroundColor); hr = stretch->put_BackgroundValue(varBackgroundValue); rasterRenderer->Update();
I can confirm that BackgroundValue is being set correctly. Calling get_BackgroundValue always returns a VARIANT array of doubles and these include the correct values if I get after I call put. The renderer is also confirmed to be set correctly as if I disable one of the bands using the renderer pointer that is clearly visible