抓取全屏并保存 (附:在图片上画方格)

//抓取全屏並保存
TCanvas *dtCanvas=new TCanvas;
Graphics::TBitmap *bitmap=new Graphics::TBitmap;
dtCanvas->Handle=GetDC(0);
bitmap->Width=Screen->Width;
bitmap->Height=Screen->Height;
TRect src=Screen->DesktopRect;
TRect dest=Rect(0,0,Screen->Width,Screen->Height);
bitmap->Canvas->CopyRect(dest,dtCanvas,src);
bitmap->SaveToFile("C://Desktop.bmp");
delete bitmap;
delete dtCanvas;

//附:在圖片上畫方格
TCanvas *pcanvas=bitmap->Canvas;
pcanvas->Brush->Style=bsDiagCross;
pcanvas->Brush->Color=clBlack;
pcanvas->Rectangle(-1,-1,bitmap->Width+1,bitmap->Height+1);

你可能感兴趣的:(c,delete)