Recent

Author Topic: How to copy specific region of desktop?  (Read 1144 times)

BosseB

  • Sr. Member
  • ****
  • Posts: 484
How to copy specific region of desktop?
« on: February 03, 2021, 08:32:45 am »
I posted this question on the Lazarus mail list but realized later that it is probably more suitable here, so this is a repeat of the post:
------------------------------------------------------------------------------

I wonder if there is a (preferably cross-platform) method to:

1) Select a region of the current desktop by placing a rectangle over it with
the mouse.

2) Copy the part of the desktop within the rectangle as an image to the
clipboard.

If so what functions do I need to accomplish the selection and the copy?

I am using Lazarus 2.0.10 and Fpc 3.2.0 on Windows 10 and Ubuntu 18.04.5

In an earlier effort to define a desktop region for locating coordinates for ripping video off screen using ffmpeg  I asked here and got a workable solution for that.
But the resulting rectangle border was not as neat as I want it to be in this case, so if there are ways to accomplish for instance the way SnagIt puts the selection rectangle on screen I would like to know how...

And once I have the coordinates to snatch the image from, how is that extraction actually done?
I.e. how to read the bitmap and put it onto the clipboard so it can be pasted into an image handling utility or onto an MS Word document etc?

I have used the clipboard a lot but only ever for text strings...

EDIT:
I found a useful thread here where the screen rect extraction is exemplified by @JurassicPork.
It uses the package BGRABitmap available via OLPM in the Package menu.
« Last Edit: February 03, 2021, 10:33:01 am by BosseB »
--
Bo Berglund
Sweden

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2695
Re: How to copy specific region of desktop?
« Reply #1 on: February 04, 2021, 10:01:25 am »
I don't know if it still works but when implementing the winapi functions for lazarus I've added a (non windows) option to copy form the desktop.
Each window has an associated device context (DC), which is the handle of a canvas. When copying image data you use a source and a destination DC. The added feature is that a DC of 0 corresponds to the desktop.
At that time only the windows and the gtk1/2 widgetsets were present so it got implemented there. Possibly also for mac-carbon (I was working at that too)

Marc
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018