RasterImage.GetPixel

RasterImage.GetPixel method

Gets an image pixel.

public Color GetPixel(int x, int y)
ParameterTypeDescription
xInt32The pixel x location.
yInt32The pixel y location.

Return Value

The pixel color for the specified location.

Examples

The following example loads a raster image and obtains the color of an arbitrary pixel.

[C#]

using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.png"))
{
    Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;

    // Get the color of the top-left pixel of the image.
    Color color = rasterImage.GetPixel(0, 0);

    // Obtain the values of the individual color components
    byte alpha = color.A;
    byte red = color.R;
    int green = color.G;
    int blue = color.B;

    System.Console.WriteLine("The color of the pixel(0,0) is A={0},R={1},G={2},B={3}", alpha, red, green, blue);
}

See Also