Returns the pixel values of the image.
Declaring type: EventOutSFImage
Namespace: Vrml.EAI.Field
Assembly: VrmlEAI.NET
Collapse/Expand Syntax
C#
public abstract int[] GetPixels ()
Return Value
The actual pixel values. This is an array of width x height integer values. The pixels are defined left to right, bottom to top, i.e. the first pixel is in the lower left corner, and the last pixel is in the upper right corner of the image. The value of each color component is between 0 (no intensity resp. completely transparent) and 255 (full intensity resp. completely opaque), inclusively. For one-component images, pixels simply consist of a single intensity value, e.g. 0x00 in hexadecimal (0 in decimal) for no intensity or 0xff in hexadecimal (256 in decimal) for full intensity. For two-component images, pixels consist of an intensity value in the upper byte, followed by an alpha value in the lower byte, e.g. 0xff80 is semi-transparent full intensity. When you have a pixel value, you can get the intensity and the alpha value like this: intensity = (pixel >> 8) & 0xff; alpha = pixel & 0xff. For three-component images, pixels consist of the red component in the highest byte, followed by green and finally blue in the lowest byte, e.g. 0xFF0000 is red, 0x00FF00 is green, and 0x0000FF is blue. When you have a pixel value, you can get the red, green and blue components like this: red = (pixel >> 16) & 0xff; green = (pixel >> 8) & 0xff; blue = pixel & 0xff. For four-component images, pixels consist of the red component in the highest byte, followed by green, blue and finally alpha in the lowest byte, e.g. 0xff000080 is semi-transparent red. When you have a pixel value, you can get the red, green, blue and alpha components like this: red = (pixel >> 24) & 0xff; green = (pixel >> 16) & 0xff; blue = (pixel >> 8) & 0xff; alpha = pixel & 0xff.
Collapse/Expand Example
The following example gets the image field of a PixelTexture node and writes the color components of all pixels to the console:
C#
Vrml.EAI.Node pixelTexture = ...;
Vrml.EAI.Field.EventOutSFImage image_changed = (Vrml.EAI.Field.EventOutSFImage)pixelTexture.GetEventOut("image_changed");
int width = image_changed.GetWidth();
System.Console.WriteLine("width = " + width + " pixels");
int height = image_changed.GetHeight();
System.Console.WriteLine("height = " + height + " pixels");
int[] pixels = image_changed.GetPixels();
int intensity, red, green, blue, alpha, i;
switch (image_changed.GetComponents())
{
    case 1:
        System.Console.WriteLine("components = 1 (intensity)");
        i = 0;
        for (int y = 0; y < height; ++y)
            for (int x = 0; x < width; ++x)
            {
                System.Console.Write("pixel @ x = " + x + ", y = " + y + ": ");
                intensity = pixels[i] & 0xff;
                System.Console.WriteLine("intensity = " + intensity);
                ++i;
            }
        break;
    case 2:
        System.Console.WriteLine("components = 2 (intensity, alpha)");
        i = 0;
        for (int y = 0; y < height; ++y)
            for (int x = 0; x < width; ++x)
            {
                System.Console.Write("pixel @ x = " + x + ", y = " + y + ": ");
                intensity = (pixels[i] >> 8) & 0xff;
                alpha = pixels[i] & 0xff;
                System.Console.WriteLine("intensity = " + intensity + ", alpha = " + alpha);
                ++i;
            }
        break;
    case 3:
        System.Console.WriteLine("components = 3 (red, green, blue)");
        i = 0;
        for (int y = 0; y < height; ++y)
            for (int x = 0; x < width; ++x)
            {
                System.Console.Write("pixel @ x = " + x + ", y = " + y + ": ");
                red = (pixels[i] >> 16) & 0xff;
                green = (pixels[i] >> 8) & 0xff;
                blue = pixels[i] & 0xff;
                System.Console.WriteLine("red = " + red + ", green = " + green + ", blue = " + blue);
                ++i;
            }
        break;
    case 4:
        System.Console.WriteLine("components = 4 (red, green, blue, alpha)");
        i = 0;
        for (int y = 0; y < height; ++y)
            for (int x = 0; x < width; ++x)
            {
                System.Console.Write("pixel @ x = " + x + ", y = " + y + ": ");
                red = (pixels[i] >> 24) & 0xff;
                green = (pixels[i] >> 16) & 0xff;
                blue = (pixels[i] >> 8) & 0xff;
                alpha = pixels[i] & 0xff;
                System.Console.WriteLine("red = " + red + ", green = " + green + ", blue = " + blue + ", alpha = " + alpha);
                ++i;
            }
       break;
}