HOW TO
This article shows how to add a JPEG image to ArcMap using IRasterLayer::CreateFromDataset.
Note:
Code in ThisDocument module will only run in the current map document. To store the code in all your map documents, open the Normal.mxt ThisDocument code module.
Code:
Public Sub AddRasterLayer()
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Dim pLayer As IRasterLayer
Dim pWF As IWorkspaceFactory
Dim pWs As IWorkspace
Dim pFW As IRasterWorkspace
Dim pDataset As IDataset
Dim pRDataset As IRasterDataset
Set pWF = New RasterWorkspaceFactory
' Enter path to the directory that contains the image file
Set pWs = pWF.OpenFromFile("C:\Images", 0)
' QI
Set pFW = pWs
' Enter Name of the image file
Set pRDataset = pFW.OpenRasterDataset("seb1.jpg")
' Create the dataset
Dim pRLayer As IRasterLayer
Set pRLayer = New RasterLayer
pRLayer.CreateFromDataset pRDataset
'Add the raster layer to the map
Set pMxDocument = ThisDocument
Set pMap = pMxDocument.FocusMap
pMxDocument.AddLayer pRLayer
End Sub
Get help from ArcGIS experts
Download the Esri Support App