Win32-Screenshot

 view release on metacpan or  search on metacpan

Screenshot.xs  view on Meta::CPAN

      memcpy( ptr_dest, ptr_raw2, ww2 * 4 );
      ptr_dest += ww2 * 4;
      ptr_raw2 += ww2 * 4;
    }

    /* output */
    EXTEND(SP, 1);
    PUSHs(sv_2mortal(newSVpvn((char*) buffer, bufferlen)));
    safefree(buffer);
    XSRETURN(1);


############################################################################

void
CaptureHwndRect(handle, xx, yy, ww, hh)
    HWND handle
    LONG xx
    LONG yy
    LONG ww
    LONG hh
PREINIT:
    HDC		hdc;
    HDC		my_hdc;
    HBITMAP	my_hbmp;
    BITMAPINFO  my_binfo;
    long	bufferlen;
    LPVOID	buffer;
    int		out;
    long	i;
    long	*p;
PPCODE:

    hdc = GetDC(handle);

    /* create in-memory bitmap for storing the copy of the screen */
    my_hdc  = CreateCompatibleDC(hdc);
    my_hbmp = CreateCompatibleBitmap(hdc, ww, hh);
    SelectObject(my_hdc, my_hbmp);

    /* copy the part of screen to our in-memory place */
    BitBlt(my_hdc, 0, 0, ww, hh, hdc, xx, yy, SRCCOPY);

    /* now get a 32bit device independent bitmap */
    ZeroMemory(&my_binfo, sizeof(BITMAPINFO));

    /* prepare a buffer to hold the screen data */
    bufferlen = hh * ww * 4;
    buffer = (LPVOID) safemalloc(bufferlen);

    /* prepare directions for GetDIBits */
    my_binfo.bmiHeader.biSize 	     = sizeof(BITMAPINFOHEADER);
    my_binfo.bmiHeader.biWidth       = ww;
    my_binfo.bmiHeader.biHeight      = -hh; /* negative because we want top-down bitmap */
    my_binfo.bmiHeader.biPlanes      = 1;
    my_binfo.bmiHeader.biBitCount    = 32; /* we want RGBQUAD data */
    my_binfo.bmiHeader.biCompression = BI_RGB;

    if(GetDIBits(my_hdc, my_hbmp, 0, hh, buffer, &my_binfo, DIB_RGB_COLORS)) {

        /* Convert RGBQUADs to format expected by Image::Magick .rgba file (BGRX -> RGBX) */
        p = buffer;
        for( i = 0 ; i < bufferlen/4 ; i++  ) {
          *p = ((*p & 0x000000ff) << 16) | ((*p & 0x00ff0000) >> 16) | (*p & 0x0000ff00) | 0xff000000;
          p++;
        }

        EXTEND(SP, 3);
        PUSHs(sv_2mortal(newSViv(my_binfo.bmiHeader.biWidth)));
        PUSHs(sv_2mortal(newSViv(abs(my_binfo.bmiHeader.biHeight))));
        PUSHs(sv_2mortal(newSVpvn((char*) buffer, bufferlen)));
        out = 1;
    } else {
      out = 0;
    }

    safefree(buffer);
    DeleteDC(my_hdc);
    ReleaseDC(handle, hdc);
    DeleteObject(my_hbmp);

    if ( out == 1 ) { XSRETURN(3); } else { XSRETURN_NO; }

############################################################################



( run in 0.794 second using v1.01-cache-2.11-cpan-98e64b0badf )