Results 1 to 3 of 3

Thread: Help with getting raw pixels from screen (lazarus)

  1. #1

    Help with getting raw pixels from screen (lazarus)

    Hey all, I've been working on a little side project while I figure things out for my PGD entry. Now though, I'm at a problem. I'm working in Lazarus (windows only) and need to get the raw screen pixel information into a buffer.

    Typically in Delphi this is easy. Create a bitmap, size it, Call BitBlt on its HDC, and then copy the scanline[0] into your working array. In lazarus of course we don't have scanline property .

    I thought that just simply creating the memory block and calling BitBlt passing the block might work, but no go. Code is below (doesn't work)

    [pascal]
    function ScreenCapRectPtr(R: TRect) : pointer;
    var
    sdc : HDC;
    begin
    result := GetMem((R.Right - R.Left)*(R.Bottom- R.Top));
    sdc := GetDC(0);
    try
    BitBlt(HDC(result), 0, 0, (R.Right - R.Left), (R.Bottom- R.Top), sdc, R.Left, R.Top, SRCCOPY);
    finally
    ReleaseDC(0, sdc);
    end;
    end;
    [/pascal]

    Anyone know where to find info on WHAT exactly an HDC really is, or have code that works in Lazarus that achieves the desired result?

    Thanks,
    - Jeremy

  2. #2

    Re: Help with getting raw pixels from screen (lazarus)

    Perhaps this link will help:

    http://wiki.lazarus.freepascal.org/D..._with_Graphics

    Specifically this info:

    Taking a screenshot of the screen

    Since Lazarus 0.9.16 you can use LCL to take screenshots of the screen on a cross-platform way. The following example code does it (works on gtk2 and win32, but not gtk1 currently):
    Code:
     uses LCLIntf, LCLType;
    
     ...
    
    var
     MyBitmap: TBitmap;
     ScreenDC: HDC;
    begin
     MyBitmap := TBitmap.Create;
     ScreenDC := GetDC(0);
     MyBitmap.LoadFromDevice(ScreenDC);
     ReleaseDC(ScreenDC);

    cheers,
    Paul

  3. #3

    Re: Help with getting raw pixels from screen (lazarus)

    Actually, yes, I have read that as well as many other articles on the subject. Unfortunately it has little to do with the price of tea in china . This has only to do with getting the pixel data from an HDC (desktop is just a good starting point, in the end its a remote HDC that will be processed).

    But, I did find that (finally) the Lazarus team has surfaced TBitmap.RawImage.Data (YEAH!) and this gives me direct access to the pixel data held within the HDC once I do a BitBlt to the surface. So, alls good now, just access that as though I were accessing Scanline .


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •