GdPicture.NET.14
GdPicture14 Namespace / GdPictureImaging Class / PaletteGetColorsCount Method
GdPicture image identifier.
Example





In This Topic
PaletteGetColorsCount Method (GdPictureImaging)
In This Topic
Returns the number of colors contained into the color palette of a GdPicture image.
Syntax
'Declaration
 
Public Function PaletteGetColorsCount( _
   ByVal ImageID As Integer _
) As Integer
public int PaletteGetColorsCount( 
   int ImageID
)
public function PaletteGetColorsCount( 
    ImageID: Integer
): Integer; 
public function PaletteGetColorsCount( 
   ImageID : int
) : int;
public: int PaletteGetColorsCount( 
   int ImageID
) 
public:
int PaletteGetColorsCount( 
   int ImageID
) 

Parameters

ImageID
GdPicture image identifier.

Return Value

Number of Imaging.Colors.
Example
Determining the palette entries count of the selected image.
Getting information about the palette entries count of the selected image and showing the result on the screen.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
    // Open an image file. An empty string allows the control to prompt for selecting a file.
    int imageID = gdpictureImaging.CreateGdPictureImageFromFile("");
 
    if (gdpictureImaging.IsPixelFormatIndexed(imageID))
    {
        int entriesCount = gdpictureImaging.PaletteGetColorsCount(imageID);
        Console.WriteLine("Image contains palete with {0} color entries.", entriesCount.ToString());
    }
    else Console.WriteLine("Image do not contain indexed colors!");
 
    // Release used resources.
    gdpictureImaging.ReleaseGdPictureImage(imageID);
}
Getting information about the specific palette entry of the selected image and showing the result on the screen.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
    // Open an image file. An empty string allows the control to prompt for selecting a file.
    int imageID = gdpictureImaging.CreateGdPictureImageFromFile("");
 
    if (gdpictureImaging.IsPixelFormatIndexed(imageID))
    {
        int entriesCount = gdpictureImaging.PaletteGetColorsCount(imageID);
 
        if (entriesCount > 255)
        {
            System.Drawing.Color entryColor = gdpictureImaging.PaletteGetEntry(imageID, 130);
            Console.WriteLine("Color value of palette entry [130] is: {0}", entryColor.ToString());
        }
        else Console.WriteLine("Image do not contain palette with 256 colors!");
    }
    else Console.WriteLine("Image do not contain indexed colors!");
 
    // Release used resources.
    gdpictureImaging.ReleaseGdPictureImage(imageID);
}
See Also