How can I
- convert a color bitmap to a grayscale bitmap
- convert a bitmap to a "disabled" bitmap
I need it to create toolbuttons in office/outlook-style.
Any hints are appreciated.
Regards
Michael Stoll
Germany
> How can I
> - convert a color bitmap to a grayscale bitmap
Look for "Gray Scale" links at
http://www.efg2.com/Lab/Library/Delphi/Graphics/Color.htm
--
efg
Earl F. Glynn E-mail: Earl...@att.net
Overland Park, KS USA
efg's Computer Lab: http://www.efg2.com/Lab
procedure Grayscale(Bitmap: TBitmap);
type
pRGBLine = ^TRGBLine;
TRGBLine = Array[word] of TRGBTriple;
pRGBQuadLine = ^TRGBQuadLine;
TRGBQuadLine = Array[word] of TRGBQuad;
var
Line : Pointer;
i, j : Integer;
palCount: Word;
MaxPal : TMaxLogPalette;
pf24 : boolean;
begin
case Bitmap.PixelFormat of
pf1bit, pf4bit, pf8bit: {Palette}
begin
{Retrieve the number of palette entries}
GetObject(Bitmap.Palette, sizeof(word), @palCount);
MaxPal.palVersion := $0300;
MaxPal.palNumEntries := PalCount;
GetPaletteEntries(Bitmap.Palette, 0, PalCount,
MaxPal.palpalentry);
FOR j := 0 to PalCount - 1 DO
with MaxPal.palPalEntry[j] do
begin
peRed := (peRed + peGreen + peBlue) div 3;
peGreen := peRed;
peBlue := peRed;
end;
Bitmap.Palette := CreatePalette(PLogPalette(@MaxPal)^);
end;
pf15bit, pf16bit:
raise Exception.Create('15bit and 16bit bitmap grayscale conversion
not supported');
pf24bit, pf32bit: {24 bit}
begin
pf24 := (Bitmap.PixelFormat = pf24bit);
FOR j := 0 TO Bitmap.Height - 1 DO
begin
Line := Bitmap.Scanline[j];
FOR i := 0 TO Bitmap.Width - 1 DO
if pf24 then
with pRGBLine(Line)[i] do
begin
rgbtRed := (rgbtRed + rgbtGreen + rgbtBlue) div 3;
rgbtgreen := rgbtred;
rgbtblue := rgbtred;
end
else
with pRGBQuadLine(Line)[i] do
begin
rgbRed := (rgbRed + rgbGreen + rgbBlue) div 3;
rgbgreen := rgbred;
rgbblue := rgbred;
end
end;
end;
end;
end;
Disabled bitmap:
procedure DrawDisabled(DC: HDC; Pos: TPoint; Bitmap: TBitmap);
begin
DrawState(DC, 0, nil, Bitmap.Handle, 0, Pos.X, Pos.Y, 0, 0,
DST_BITMAP or DSS_DISABLED);
end;
Hope it helps :)
Michael Stoll <Michae...@onken.de> escreveu nas notícias de
mensagem:396b009f@dnews...
> Hi all!
>
> How can I
> - convert a color bitmap to a grayscale bitmap
Thanks for your posting. But I have one more question:
What about Bitmaps with the pfDevice or pfCustom pixel format?
How can I convert them?
Thanks in advance
Michael