I have a problem when trying to export a layer with renderer to a file. Basically, what I have at start is a correct IRasterDataset. Then I define a stretch renderer in form of IMultiPortColorRamp and apply it to IRasterLayer created from input IRasterDataset.
Please take a look at my code:
//Create and fill the IRasterLayer object
IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromDataset(productDataset);
rasterLayer.Renderer = StretchRenderer(rasterLayer.Raster);
//Prepare the export
var rle = new RasterLayerExport();
IRasterLayerExport2 rle2 = rle as IRasterLayerExport2;
rle2.RasterLayer = rasterLayer;
rle2.Extent = rasterLayer.VisibleExtent;
rle2.Force2RGB = false;
IRasterStorageDef rsd = new RasterStorageDef();
rsd.CompressionType = esriRasterCompressionType.esriRasterCompressionUncompressed;
rle2.StorageDef = rsd;
//Export file
IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
IWorkspace workspace = workspaceFactory.OpenFromFile(fileFolder, 0);
var test = rle2.Export(workspace, "FILEX.TIF", "TIFF");
The StretchRenderer function uses the same code as CreateMultiPartColorRamp here: http://www.onspatial.com/2011/02/arcobjects-create-multipart-color-ramp.html?m=2
This results in a proper export of GeoTIFF but without the renderer applied. The exported file is usable in ArcMap and it has the default stretched visualization available. What can I do to export this raster altogether with the renderer?