0

Is there any way that we could crop a particular RECT from the image captured using the Desktop Duplication and renders it back to the window after applying some effects.

please have a look at this picture:

enter image description here

Take notepad as the example ,so as per the above picture i want to capture the red rectangular area (the window RECT area) and renders it back to a window. and when the window is moved from one position to another the capturing source RECT should also move along with the window (exactly like the windows magnifier window).

I have already referred to DXGI desktop duplication sample and it looks very complicated.

Note: I will use WDA_EXCLUDEFROMCAPTURE to remove the window from the capturing RECT so that I will be able to get the visual behind the window

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
trickymind
  • 557
  • 5
  • 21
  • You can set the window position of Notepad and pass the moving coordinates of the window to notepad. Or draw a transparent layered window yourself, render it, and then calculate the coordinates. – Strive Sun Oct 22 '20 at 10:00
  • i'm not sure how to do that. – trickymind Oct 22 '20 at 10:01
  • [SetWindowPos](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos) or [MoveWindow](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-movewindow) – Strive Sun Oct 22 '20 at 10:02
  • no not that method – trickymind Oct 22 '20 at 10:05
  • i can acquire the entire desktop image through desktop duplication and what i need is i only have to get the RECT area where window is placed. i dont know how to get the particular portion from the full image and render it back to another window – trickymind Oct 22 '20 at 10:07
  • `exactly like the windows magnifier window` Magnification API can meet your need. Can you share the reason why you must use directx? – Strive Sun Oct 23 '20 at 09:03
  • I can get the bitmap from MagImageCallback but if I move the window out of the desktop it causes some exception, I have mentioned it here:https://stackoverflow.com/questions/64318817/windows-magnifier-window-cause-exception-when-setting-magsetimagescalingcallback?noredirect=1#comment114011457_64318817 – trickymind Oct 23 '20 at 12:04
  • And that callback is deprecated and will be removed in the future – trickymind Oct 23 '20 at 12:06
  • @trickymind did you found something here? – Santosh Dhanawade Sep 04 '21 at 13:51
  • ya i found a better way using direct composition, you may have a look at these demos: https://github.com/Extrimis/Win32-Acrylic-Effect – trickymind Sep 04 '21 at 16:14
  • this one is the actual code : https://blog.adeltax.com/dwm-thumbnails-but-with-idcompositionvisual/ – trickymind Sep 04 '21 at 16:15
  • i built the acrylic on top of it – trickymind Sep 04 '21 at 16:15
  • it uses dwm private API – trickymind Sep 04 '21 at 16:16

1 Answers1

2

The API is designed in such way that you capture composed image for the entire monitor with a really small processing overhead. There is no option to capture a region of interest (ROI), and there is no much sense in this either: you would gain nearly nothing, specifically there would be no performance benefit.

When you capture a frame you have a standard texture and you are free to do whatever you want with the data. Specifically you can extract your ROI. You can also check updated/moved rectangles against your ROI coordinates. You can map texture data and process it as byte array too. That is, it is fairly easy to crop and there are multiple ways to do this - it is just not the task Desktop Duplication API is designed for.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Hidden in this answer is the implication that the desktop duplication API can duplicate individual monitors on the windows desktop, rather than the entire windows desktop. Is that the case? – unsynchronized Jun 07 '22 at 21:24