Wednesday, November 25, 2009

CreatePalette function

The CreatePalette function creates a logical color palette.

HPALETTE CreatePalette(
 CONST LOGPALETTE *lplgpl   // pointer to logical color palette
 );

Parameters

lplgpl Points to a LOGPALETTE structure that contains information about the colors in the logical palette.

Return Values

If the function succeeds, the return value is a handle that identifies a logical palette.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying the RASTERCAPS constant. Once an application creates a logical palette, it can select that palette into a device context by calling the SelectPalette function. A palette selected into a device context can be realized by calling the RealizePalette function.
When you no longer need the palette, call the DeleteObject function to delete it.
 

PALETTEENTRY structure

The PALETTEENTRY structure specifies the color and usage of an entry in a logical color palette. A logical palette is defined by a LOGPALETTE structure.

typedef struct tagPALETTEENTRY { // pe
 BYTE peRed;
 BYTE peGreen;
 BYTE peBlue;
 BYTE peFlags;
} PALETTEENTRY;

Members

 peRed Specifies a red intensity value for the palette entry.

 peGreen Specifies a green intensity value for the palette entry.

 peBlue Specifies a blue intensity value for the palette entry.

 peFlags Specifies how the palette entry is to be used.

The peFlags member may be set to NULL or one of the following values:

Value Meaning

PC_EXPLICIT Specifies that the low-order word of the logical palette entry designates a hardware palette index. This flag allows the application to show the contents of the display device palette.

PC_NOCOLLAPSE
Specifies that the color be placed in an unused entry in the system palette instead of being matched to an existing color in the system palette. If there are no unused entries in the system palette, the color is matched normally. Once this color is in the system palette, colors in other logical palettes can be matched to this color.

PC_RESERVED
Specifies that the logical palette entry be used for palette animation. This flag prevents other windows from matching colors to the palette entry since the color frequently changes. If an unused system-palette entry is available, the color is placed in that entry. Otherwise, the color is not available for animation.
 

LOGPALETTE structure

The LOGPALETTE structure defines a logical color palette.

typedef struct tagLOGPALETTE {  // lgpl
 WORD palVersion;
 WORD palNumEntries;
 PALETTEENTRY palPalEntry[1];
} LOGPALETTE;


Members

palVersion Specifies the Windows version number for the structure (currently 0x300).

palNumEntries Specifies the number of entries in the logical color palette.

palPalEntry Specifies an array of PALETTEENTRY structures that define the color and usage of each entry in the logical palette.

Remarks
 
The colors in the palette-entry table should appear in order of importance because entries earlier in the logical palette are most likely to be placed in the system palette.
 

Wednesday, November 18, 2009

TBrush

Determines the color and pattern for filling graphical shapes and backgrounds.

__property TBrush* Brush = {read=FBrush, write=SetBrush};

Description


Set the Brush property to specify the color and pattern to use when drawing the background or filling in graphical shapes. The value of Brush is a TBrush object. Set the properties of the TBrush object to specify the color and pattern or bitmap to use when filling in spaces on the canvas.

Note: Setting the Brush property assigns the specified TBrush object, rather than replacing the current TBrush object.
Note: Brush must have a Style of bsSolid before you can paint.


Example:
Image1->Canvas->Brush->Color =(TColor)RGB(130,67,33);
設定 Image1 畫布上筆刷的顏色為 (130,67,33)。

Tuesday, November 17, 2009

TCanvas::Pixels

TCanvas 有一個 property , 一般表示成 TCanvas::Pixels, 是我們常會用到的, Pixels 這個 property 可以讀出, 也可以寫入某個特定位置的色彩值, 因此這個 property 的類別為 TColor。在 BCB Help 中的說明如下:
TCanvas::Pixels
Specifies the color of the pixels within the current ClipRect.

__property TColor Pixels[int X][int Y] = {read=GetPixel, write=SetPixel};

Description
Read Pixels to learn the color on the drawing surface at a specific pixel position within the current clipping region. If the position is outside the clipping rectangle, reading the value of Pixels returns -1.

Write Pixels to change the color of individual pixels on the drawing surface. Use Pixels for detailed effects on an image. Pixels may also be used to determine the color that should be used for the FillRect method.

Not every device context supports the Pixels property. Reading the Pixels property for such a device context will return a value of -1. Setting the Pixels property for such a device context does nothing.