How to convert a raster to a JP2000 file


This sample shows how to convert a raster to a JP2000 file with specified compression quality. The sample will work with other output raster format (e.g. IMG, TIFF, GRID, BMP, JPEG, GIF, PNG) with some modification

How to use

  1. Paste this function in your code.
  2. Call this function from your code.
[VBA]
' Libraries needed to run the code:
' ESRI.ArcGIS.Geodatabase, ESRI.ArcGIS.DataSourcesRaster

Public Sub ConvertToJP2(pRasterDs As IRasterDataset, pWs As IWorkspace, sJP2name As String, iQuality As Integer)
    
    ' Convert a Raster to a JP2000 file with specified quality
    ' pRasterDs is the input raster dataset
    ' pWs is the output workspace where the JP2000 file will reside
    ' sJP2name is the output JP2000 file name
    ' iQuality is the compression quality of the JP2000 file
    
    Dim pSaveAs As ISaveAs2
    
    'QI ISaveAs2
    Set pSaveAs = pRasterDs
    
    'Create storagedef
    Dim pStorageDef As IRasterStorageDef2
    Set pStorageDef = New RasterStorageDef
    pStorageDef.CompressionType = esriRasterCompressionJPEG2000
    pStorageDef.CompressionQuality = iQuality
    
    'Save to JP2000
    pSaveAs.SaveAsRasterDataset sJP2name, pWs, "JP2", pStorageDef
    
    Set pSaveAs = Nothing
    
End Sub