This document is archived and information here might be outdated.  Recommended version.


How to identify pixel values using a raster object (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with image and raster data > Processing raster data > Geodata transformations > How to identify pixel values using a raster object

How to identify pixel values using a raster object


Summary
This topic shows how to identify pixel values directly from a raster object.

Identifying pixel values on a raster

IRaster2.GetPixelValue can be used to retrieve a pixel value at a given row and column in a pixel space. To get the pixel value by giving x and y coordinates in a map space, use the following code:
[C#]
public static void IdentifyPixelValue(IRaster raster, double xMap, double yMap)
{
    IRaster2 raster2=(IRaster2)raster;

    //Get the column and row by giving x,y coordinates in a map space.
    int col=raster2.ToPixelColumn(xMap);
    int row=raster2.ToPixelRow(yMap);

    //Get the value at a given band.
    double pixelValue=raster2.GetPixelValue(0, col, row);
}
[VB.NET]
Public Sub IdentifyPixelValue(ByVal raster As IRaster, ByVal xMap As Double, ByVal yMap As Double)
    
    Dim raster2 As IRaster2=CType(raster, IRaster2)
    
    'Get the column and row by giving x,y coordinates in a map space.
    Dim col As Integer=raster2.ToPixelColumn(xMap)
    Dim row As Integer=raster2.ToPixelRow(yMap)
    
    'Get the value at a given band.
    Dim pixelValue As Double=CDbl(raster2.GetPixelValue(0, col, row))
    
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine