in reply to Win32::GuiTest - Processing screen captures in memory?

Rather than saving it to a file, copy it to the clipboard and then retrieve it from there using Win32::ClipBoard:

sub grabWindowRegion { my $cb = new Win32::ClipBoard; my $ds = new Win32::GuiTest::DibSect; $ds->CopyClient(shift,[@_]); $ds->ToClipboard(); my $image = Win32::Clipboard::GetBitmap(); return parseBMP( $image ); }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Win32::GuiTest - Processing screen captures in memory?
by SuicideJunkie (Vicar) on Mar 19, 2011 at 23:38 UTC

    I'm not sure what's wrong with that... the image does end up on the clipboard, but I can't get it back out into $image.

    grabWindowRegion(0, 0,0,64,64); sub grabWindowRegion { my $ds = new Win32::GuiTest::DibSect; $ds->CopyClient(shift,[@_]); $ds->ToClipboard(); print Win32::Clipboard::IsBitmap() ? "Bitmap\n" : "Not Bitmap\n"; my $image = Win32::Clipboard::GetBitmap(); #Same results with just Get() print Dumper $image; die "\n"; # $ds->SaveAs('temp.bmp'); # return parseBMP('temp.bmp'); }
    Gives:
    Not Bitmap $VAR1 = '';

    The image is definitely on the clipboard though, since if I open mspaint, I can Ctrl-V and get the "my computer" icon perl captured from my desktop...

      You are calling GetBitmap as a function. The documentation shows it being called as a class method. I suspect that is the cause of your problem as the following snippet successfully retrieves, saves and displays any image I place on the clipboard:

      #! perl -slw use strict; use Win32::Clipboard; my $cb = Win32::Clipboard->new(); my $bmp = $cb->GetBitmap; open O, '>:raw', 'junk.bmp' or die $!; print O $bmp; close O; system 'junk.bmp';

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        All the functions can be used either with their full name (eg. Win32::Clipboard::Get) or as methods of a Win32::Clipboard object.

        That said, I did try it as an object anyways, and got the same result again.

        If you call the IsBitmap() function, does it recognize the clipboard image on your system?

        I've also gone and updated everything available through PPM, and reinstalled guitest and clipboard to be sure I've got the latest. Running XP, in case that matters.

      IIRC, clipboard/bitmap is 24-bit type bitmap ... can your parseBMP deal with it?