A
Alucard
Unregistered / Unconfirmed
GUEST, unregistred user!
这是你回答我那个问题的代码,虽然解决问题了,但是有几处有点迷糊,还望大侠指点一下。
var
hdcScr, hdcMem: HDC;
bmpMem, bmpOld: HBITMAP;
cnv: TCanvas;
begin
hdcScr := GetDC(0);
bmpMem := CreateCompatibleBitmap(hdcScr, 200, 200);
ReleaseDC(0, hdcScr);
hdcMem := CreateCompatibleDC(0);
bmpOld := SelectObject(hdcMem, bmpMem);
cnv := TCanvas.Create;
cnv.Handle := hdcMem;
cnv.Brush.Color := clYellow;
cnv.Pen.Color := clRed;
cnv.FillRect(Rect(0, 0, 200, 200));
cnv.Ellipse(0, 0, 200, 200);
Self.Canvas.CopyRect(Rect(100, 100, 300, 300), cnv, Rect(0, 0, 200, 200));
cnv.Free;
SelectObject(hdcMem, bmpOld);
DeleteDC(hdcMem);
DeleteObject(bmpMem);
end;
== 以下是我的疑问 ============================================================
hdcScr := GetDC(0);
bmpMem := CreateCompatibleBitmap(hdcScr, 200, 200);
ReleaseDC(0, hdcScr);
hdcMem := CreateCompatibleDC(0);
bmpOld := SelectObject(hdcMem, bmpMem);
我以前用的是:
hdcScr := CreateCompatibleDC(0);
bmpMem := CreateCompatibleBitmap(hdcScr, 200, 200);
SelectObject(hdcScr, bmpMem);
结果是不正常的,为什么?
还有这块:
bmpOld := SelectObject(hdcMem, bmpMem);
...
SelectObject(hdcMem, bmpOld);
这两句的工作是做什么的?
var
hdcScr, hdcMem: HDC;
bmpMem, bmpOld: HBITMAP;
cnv: TCanvas;
begin
hdcScr := GetDC(0);
bmpMem := CreateCompatibleBitmap(hdcScr, 200, 200);
ReleaseDC(0, hdcScr);
hdcMem := CreateCompatibleDC(0);
bmpOld := SelectObject(hdcMem, bmpMem);
cnv := TCanvas.Create;
cnv.Handle := hdcMem;
cnv.Brush.Color := clYellow;
cnv.Pen.Color := clRed;
cnv.FillRect(Rect(0, 0, 200, 200));
cnv.Ellipse(0, 0, 200, 200);
Self.Canvas.CopyRect(Rect(100, 100, 300, 300), cnv, Rect(0, 0, 200, 200));
cnv.Free;
SelectObject(hdcMem, bmpOld);
DeleteDC(hdcMem);
DeleteObject(bmpMem);
end;
== 以下是我的疑问 ============================================================
hdcScr := GetDC(0);
bmpMem := CreateCompatibleBitmap(hdcScr, 200, 200);
ReleaseDC(0, hdcScr);
hdcMem := CreateCompatibleDC(0);
bmpOld := SelectObject(hdcMem, bmpMem);
我以前用的是:
hdcScr := CreateCompatibleDC(0);
bmpMem := CreateCompatibleBitmap(hdcScr, 200, 200);
SelectObject(hdcScr, bmpMem);
结果是不正常的,为什么?
还有这块:
bmpOld := SelectObject(hdcMem, bmpMem);
...
SelectObject(hdcMem, bmpOld);
这两句的工作是做什么的?