📄 copyimageu.pas
字号:
unit CopyImageU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ForegroundImage: TBitmap; // holds the foreground image
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
{create the foreground bitmap and load it}
ForegroundImage := TBitmap.Create;
ForegroundImage.LoadFromFile('Foreground.bmp');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{free the foreground bitmap}
ForegroundImage.Free;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
TempBitmap: HBITMAP; // a handle to the copied image
OldBitmap: HBITMAP; // holds the old bitmap from the DC
OffscreenDC: HDC; // a handle to an offscreen device context
begin
{make a monochrome mask of the foreground image}
TempBitmap := CopyImage(ForegroundImage.Handle, IMAGE_BITMAP,
ForegroundImage.Width, ForegroundImage.Height,
LR_MONOCHROME);
{create an memory device context}
OffscreenDC := CreateCompatibleDC(0);
{select the monochrome mask image into the memory device context}
OldBitmap := SelectObject(OffscreenDC, TempBitmap);
{blit the monochrome mask onto the background image. $00220326 is a raster
operation that inverts the pixels of the source rectangle and then combines
these pixels with those of the destination bitmap using the boolean AND
operator. this carves out an area for the regular foreground bitmap}
BitBlt(Image1.Picture.Bitmap.Canvas.Handle, 150, 50, 100, 100, OffscreenDC,
0, 0, $00220326);
{blit the foreground bitmap onto the background by combining the foreground
and background pixels with the boolean OR operator. the result is the
foreground orb being copied onto the background while the edges of the
orb image appear transparent}
BitBlt(Image1.Picture.Bitmap.Canvas.Handle, 150, 50, 100, 100,
ForegroundImage.Canvas.Handle, 0, 0, SRCPAINT);
{select the previous bitmap back into the memory device context}
SelectObject(OffscreenDC, OldBitmap);
{delete the mask bitmap and the memory device context}
DeleteObject(TempBitmap);
DeleteDC(OffscreenDC);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -