首页 > 代码库 > Delphi API 之 BitBlt

Delphi API 之 BitBlt

BitBlt

该函数对指定的源设备环境区域中的像素进行位块(bit_block)转换,以传送到目标设备环境

BitBlt(  DestDC: HDC;                  {目标 DC}  X, Y, Width, Height: Integer; {目标位置与大小}  SrcDC: HDC;                   {源 DC}  XSrc, YSrc: Integer;          {源起始位置}  Rop: DWORD                    {光栅操作码, 也就是源像素与目标像素的混合方式}): BOOL;

var  bit1,bit2: TBitmap;  cvs1,cvs2,cvs3: TCanvas;procedure TForm1.FormCreate(Sender: TObject);begin   with ListBox1.Items do  begin    Add(SRCCOPY    );    Add(SRCPAINT   );    Add(SRCAND     );    Add(SRCINVERT  );    Add(SRCERASE   );    Add(NOTSRCCOPY );    Add(NOTSRCERASE);    Add(MERGECOPY  );    Add(MERGEPAINT );    Add(PATCOPY    );    Add(PATPAINT   );    Add(PATINVERT  );    Add(DSTINVERT  );    Add(BLACKNESS  );    Add(WHITENESS  );end;   Panel1.Caption := ‘‘;  Panel2.Caption := ‘‘;  Panel3.Caption := ‘‘;  bit1 := TBitmap.Create;  bit1.Width := Panel1.ClientWidth;  bit1.Height := Panel1.ClientHeight;  bit2 := TBitmap.Create;  bit2.Width := Panel2.ClientWidth;  bit2.Height := Panel2.ClientHeight;  cvs1 := TCanvas.Create;  cvs2 := TCanvas.Create;  cvs3 := TCanvas.Create;  cvs1.Handle := GetDC(Panel1.Handle);  cvs2.Handle := GetDC(Panel2.Handle);  cvs3.Handle := GetDC(Panel3.Handle);end;procedure TForm1.FormPaint(Sender: TObject);const  ColorArr: array[0..5] of TColor = (clRed, clGreen, clBlue, clYellow, clFuchsia, clPurple);var  wi,hi: Integer;  I: Integer;begin  wi := bit1.Width div 4;  hi := bit1.Height div 4;  bit1.Canvas.Pen.Width := 10;  for I := 1 to 3 do  begin    bit1.Canvas.Pen.Color := ColorArr[i-1];    bit1.Canvas.MoveTo(wi*i, 0);    bit1.Canvas.LineTo(wi*i, bit1.Height);    bit1.Canvas.Pen.Color := ColorArr[i+2];    bit1.Canvas.MoveTo(0, hi*i);    bit1.Canvas.LineTo(bit1.Width, hi*i);  end;  bit2.Canvas.Pen.Width := 15;  bit2.Canvas.Ellipse(15, 15, bit2.Width-15, bit2.Height-15);  cvs1.Draw(0, 0, bit1);  cvs2.Draw(0, 0, bit2);end;procedure TForm1.ListBox1Click(Sender: TObject);var  Rop: Cardinal;begin  Repaint;  Rop := SRCCOPY;  case ListBox1.ItemIndex of    0 : Rop := SRCCOPY    ;    1 : Rop := SRCPAINT   ;    2 : Rop := SRCAND     ;    3 : Rop := SRCINVERT  ;    4 : Rop := SRCERASE   ;    5 : Rop := NOTSRCCOPY ;    6 : Rop := NOTSRCERASE;    7 : Rop := MERGECOPY  ;    8 : Rop := MERGEPAINT ;    9 : Rop := PATCOPY    ;    10: Rop := PATPAINT   ;    11: Rop := PATINVERT  ;    12: Rop := DSTINVERT  ;    13: Rop := BLACKNESS  ;    14: Rop := WHITENESS  ;  end;  cvs3.Draw(0, 0, bit1);  BitBlt(cvs3.Handle, (bit1.Width - bit2.Width) div 2, (bit1.Height - bit2.Height) div 2,    bit2.Width, bit2.Height, bit2.Canvas.Handle, 0, 0, Rop);end;procedure TForm1.FormDestroy(Sender: TObject);begin bit1.Free;  bit2.Free;  cvs1.Free;  cvs2.Free;  cvs3.Free;end;end.

 

Delphi API 之 BitBlt