How to save a raster with a specified NoData value


This sample shows how one can save out a raster with a specified NoData value.

How to use

  1. Call this subroutine from your code.
[VBA]
/ / Required libraries
ESRI.ArcGIS.esriSystem, ESRI.ArcGIS.Geodatabase, ESRI.ArcGIS.DataSourcesRaster

Sub SaveAsRasterWithNoData(pRaster As IRaster)
    Dim pProp As IRasterProps
    Dim pSaveAs As ISaveAs
    
    Set pProp = pRaster
    
    'set NoData value
    pProp.NoDataValue = 255
    
    'or define different NoData values for each band.
    Dim Value(2) As Integer
    Value(0) = 1
    Value(1) = 1
    Value(2) = 32
    pProp.NoDataValue = Value
    
    Set pSaveAs = pRaster
    pSaveAs.SaveAs "c:\temp\nodata3.img", Nothing, "IMAGINE Image"
End Sub