2010. július 21., szerda

Accept mouse clicks only on non-transparent pixels of an image


Problem/Question/Abstract:

How to accept mouse clicks only on non-transparent pixels of an image

Answer:

Use a TImage descendant where you replace

procedure TMouseImage.CMHitTest(var Msg: TWMMouse);
begin
  inherited;
  if Assigned(PicUp) and Assigned(PicUp.Bitmap) and Transparent and
    (Msg.XPos < PicUp.Bitmap.Width) and (Msg.YPos < PicUp.Bitmap.Height) and
    (PicUp.Bitmap.Canvas.Pixels[Msg.XPos, Msg.YPos] =
    (Picture.Bitmap.TransparentColor and $FFFFFF)) then
    Msg.Result := 0;
end;

Now clicks on the control only work for non-transparent pixels even for holes in the picture.

Nincsenek megjegyzések:

Megjegyzés küldése