From: David Ullrich Subject: Re: Mono bitmaps Date: 06 Feb 1999 00:00:00 GMT Message-ID: <36BC81C4.4FDF@math.okstate.edu> Content-Transfer-Encoding: 7bit References: <79hc0m$pfd8@forums.borland.com> Content-Type: text/plain; charset=us-ascii Organization: OSU Mime-Version: 1.0 Newsgroups: borland.public.delphi.graphics Louis wrote: > > Why does a bitmap, when set to pixelformat -> pf1bit, sometimes not display > as black and white? (Sometimes it displays in two colors - i.e. bue&green) > I really need to have them display black and white all the time. > Is there something else I am forgetting? A 1-bit bitmap still has a palette - it's usually black and white. If you make a _new_ 1bpp bitmap you get black and white automatically. You can easily make a two-color black&white palette and set the bitmap's Palette to it. Like you use unit GrayPal; interface uses Windows; function GetGrayPalette: THandle; //creates and returns a HPALETTE that //the caller needs to Delete!(Object) function GetBWXPalette: THandle; //2-entry palette with entries[0]=1, entries[1]=0 implementation var GrayColorTable: TMaxLogPalette; type PBWXLogPalette = ^TBWXLogPalette; TBWXLogPalette = packed record palVersion: Word; palNumEntries: Word; palPalEntry: array [0..1] of TPaletteEntry; end; var BWXColorTable: TBWXLogPalette; function GetGrayPalette: THandle; begin result:= CreatePalette(PLogPalette(@GrayColorTable)^); end; function GetBWXPalette: THandle; begin result:= CreatePalette(PLogPalette(@BWXColorTable)^); end; function MakeGrayPalette: TMaxLogPalette; var j: byte; begin with result do begin palVersion:= $300; palNumEntries:= 256; for j:= 0 to 255 do begin with palPalEntry[j] do begin peRed:= j; peGreen:= j; peBlue:= j; peFlags:= 0; end; end; end; end; function MakeBWXPalette: TBWXLogPalette; var j: byte; begin with result do begin palVersion:= $300; palNumEntries:= 2; for j:= 0 to 1 do begin with palPalEntry[j] do begin peRed:= (1 - j)*255; peGreen:= (1 - j)*255; peBlue:= (1 - j)*255; peFlags:= 0; end; end; end; end; initialization GrayColorTable:= MakeGrayPalette; BWXColorTable:= MakeBWXPalette; end. and then you say with YourBitmap do begin PixelFormat:= pf1Bit; Palette:= GetBWXPalette; end; When I do this I tend to DeleteObject(Palette) when I'm finished to be on the safe side, I don't think it's actually necessary. Don't ask me what the X in "BWX" means, I have no idea. Must have meant something at the time... -- David Ullrich sig.txt still not found