这段代码错哪了?为何抓不到图?
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TRect MyRect, MyOther;
MyRect = Rect(10,10,100,100);
MyOther = Rect(10,111,100, 201);
Graphics::TBitmap *fullscreen=new Graphics::TBitmap();
Graphics::TBitmap *cc=new Graphics::TBitmap();
HDC dc=GetDC(0);//获取屏幕的DC handle
int x=Screen-> Width;
int y=Screen-> Height;
fullscreen-> Handle =CreateCompatibleBitmap(dc,x,y);//抓屏
BitBlt(fullscreen-> Canvas-> Handle,0,0,fullscreen-> Width,fullscreen-> Height,dc,0,0,SRCCOPY);//复制图像
cc-> Canvas-> BrushCopy(MyRect, fullscreen, MyRect, clNone);
Form1-> Canvas-> CopyRect(MyOther, cc-> Canvas, MyRect);
delete fullscreen;
delete cc;
}
[解决办法]
没有定义cc大小:
Graphics::TBitmap *cc=new Graphics::TBitmap();
cc-> Width=MyRect.Width();
cc-> Height=MyRect.Height();
如果只是把屏幕放到Form1上的话下面这样比较简洁
TCanvas *C=new TCanvas;
C-> Handle=GetDC(0);
Form1-> Canvas-> CopyRect(Form1-> ClientRect,C,Form1-> ClientRect);
delete C;
[解决办法]
是不是要把整个屏幕抓下的图缩放到指定大小的位置内的?有个str...draw的api吧,记不得了