码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi API 之 BitBlt

时间:2014-10-17 23:13:51      阅读:450      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   ar   for   sp   

BitBlt

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

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

bubuko.com,布布扣

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

标签:des   style   blog   http   color   io   ar   for   sp   

原文地址:http://www.cnblogs.com/delphi2014/p/4032171.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!