Screen shoot

hello guys
i need to take a screen shoot of the entire desktop.
I wrote the following code,
void __fastcall TForm1::Button1Click(TObject *Sender)
HDC hScreenDC = ::GetDC(NULL); // get Entire Desktop screen shoot
COLORREF RGB; // return value of GetPixel()
TImage *image = new TImage(this);

image->Width = Screen->Width;
image->Height = Screen->Height;

for(int x=0; xWidth; x++)
for(int y=0; yHeight; y++) {
RGB = GetPixel(hScreenDC, x, y);
image->Canvas->Pixels[x][y] = (TColor)RGB;
but is has some drawbacks:
1- takes too long time to finish its job (5 secs)
2- if i moved any windows, it may cause some unpredictable effect on the captured screen.
3- the result file is HUGE = 3 MB.

any one have any better trick ?!! :-( :(


  • [link=]GetDIBits[/link] is a lot faster than GetPixel.
    I don't know anything about VCL/TImage, but a quick Google
    search found this on how to integrate it with GetDIBits:
  • Greetings. I apologise for my English, I not so well speak. Try to keep a picture so: [code]TImage *pImage = NULL;
    TCanvas *pCanvas = NULL;

    pImage = new TImage(this);
    pCanvas = new TCanvas();

    pCanvas->Handle = GetWindowDC( GetDesktopWindow() );

    pImage->Width = pCanvas->ClipRect.Width();
    pImage->Height = pCanvas->ClipRect.Height();
    pImage->Canvas->CopyRect(pCanvas->ClipRect, pCanvas, pCanvas->ClipRect);
    delete pImage;
    delete pCanvas;[/code]
  • thanx to all contributers
    and very special thanx to FleXic
    your method is very easy, effective, and fast
    thank you again
    Mohammad Nasim
  • by the way, "windows SDK documentation" mentioned that it is very important to release DC back to system by adding the following line of code
    ReleaseDC(GetDesktopWindow(), pCanvas->Handle);
    before you delete your two pointers.

    thanks again
  • I am glad that have helped you)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!