From: "Henrik Palmér" Newsgroups: borland.public.delphi.graphics References: <3ac8ec1a_2@dnews> Subject: SV: Maskblt - proper way Date: Tue, 3 Apr 2001 21:31:54 +0200 Lines: 61 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 212.151.45.39 Message-ID: <3aca2470_2@dnews> X-Trace: dnews 986326128 212.151.45.39 (3 Apr 2001 12:28:48 -0700) Path: dnews Xref: dnews borland.public.delphi.graphics:37006 A better solution, compatible with Win9x, would be to call BitBlt twice: procedure MaskBltC(Dest: HDC; ABitmap: TBitmap; TransparentColor: TColor; X, Y: Integer); var Bitmap, Mask: TBitmap; begin Bitmap := TBitmap.Create; Mask := TBitmap.Create; try Bitmap.Assign(ABitmap); Mask.Assign(ABitmap); Mask.Mask(TransparentColor); if TransparentColor <> clBlack then begin BitBlt(Mask.Canvas.Handle, 0, 0, Mask.Width, Mask.Height, 0, 0, 0, DSTINVERT); BitBlt(Bitmap.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height, Mask.Canvas.Handle, 0, 0, SRCAND); BitBlt(Mask.Canvas.Handle, 0, 0, Mask.Width, Mask.Height, 0, 0, 0, DSTINVERT); end; BitBlt(Dest, X, Y, Mask.Width, Mask.Height, Mask.Canvas.Handle, 0, 0, SRCAND); BitBlt(Dest, X, Y, Bitmap.Width, Bitmap.Height, Bitmap.Canvas.Handle, 0, 0, SRCPAINT); finally Bitmap.Free; Mask.Free; end; end; "Shannon Broskie" skrev i meddelandet news:3ac8ec1a_2@dnews... > What is the proper way to transparently draw a bitmap? > > I need to use Maskblt because the final image will wind up being in the > form's title bar. > > I'm having trouble generating the mask... > Here's some code I've been using to play around with it... > > var > DC : HDC; > begin > image1.Picture.Bitmap.Assign (imgLock.Picture.Bitmap); > image1.Picture.Bitmap.Mask (imgLock.Picture.Bitmap.TransparentColor); > DC := GetWindowDC (Self.Handle); > MaskBlt (DC, 100, 100, imgLock.Width, imgLock.Height, > imgLock.Canvas.Handle, 0, 0, > image1.Canvas.Handle, 0, 0, SRCCOPY); > > > The mask method of image1 seems to generate a mask that maskblt does not > like... Any ideas? > > Thanks in advance...