使用mask来制作图像透明

使用mask来制作图像透明_第1张图片

背景图

使用mask来制作图像透明_第2张图片 

带mask的图像

使用mask来制作图像透明_第3张图片

 效果图

type

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    bgBitmap:HGDIOBJ;
    pMan:HGDIOBJ;
    DC:HDC;
    X,Y:Integer;
    { Private declarations }
  public
    { Public declarations }
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  bgBitmap:=LoadImage(0,'BG.BMP',IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
  pMan:=LoadImage(0,'man.bmp',IMAGE_BITMAP,208,154,LR_LOADFROMFILE);
  DC:=CreateCompatibleDC(GetDC(Self.Handle));
  X:=20;
  Y:=20;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  ReleaseDC(Self.Handle,DC);
  DeleteObject(bgBitmap);
  DeleteObject(pMan);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  SelectObject(DC,bgBitmap);
  BitBlt(Self.Canvas.Handle,0,0,768,540,DC,0,0,SRCCOPY);
  SelectObject(DC,pMan);
  BitBlt(Self.Canvas.Handle,150,150,104,154,DC,104,0,SRCAND);
  BitBlt(Self.Canvas.Handle,150,150,104,154,DC,0,0,SRCPAINT);
end;

你可能感兴趣的:(使用)