procedure TCharSet.GetChar(DestCanvas :TCanvas; DestRect :TRect;
ForeColor, BkgColor :TColor);
var i,j :integer;
SourceRect := RectIndex[CharIndex];
With DestCanvas do
for i := 0 to 15 do
for j := 0 to 15 do
if CSBitmap.Canvas.Pixels[SourceRect.Left + i, SourceRect.Top + j] = 0
then Pixels[DestRect.Left + i, DestRect.Top + j] := BkgColor
else Pixels[DestRect.Left + i, DestRect.Top + j] := ForeColor;
CSBitmap is a bitmap containing the whole character set. RectIndex contains any array of rectangles used to extract a specific character from the bitmap. DestCanvas and DestRect specify where I want to copy the character (in my program it will be called from a StringGrid OnDrawCell event).
The bitmap in CSBitmap is stored using a palette of 16 colors, but only two colors are used (palette indexes of 0 and 1, I believe).
Anyway, this does exactly what I want to do, but too slow. I believe that if I change the palette of the bitmap accordingly, I can just use CopyRect instead of manually checking each of the pixels.
For example, if I could do something like this:
CSBitmap.Palette := BkgColor;
CSBitmap.Palette := ForeColor;
I know that is not the syntax for changing the colors in the palette. I looked at the help file for info on palettes and found it very confusing. I do not want to create or select a palette, I just want to change the values in it.
How do I do this?
Also, is there an even faster way to do it than CopyRect?