0

I can take a screenshot of all the screen or for an application using windows API, as detailed here and here.

However, my question is how can I take a screenshot of an image in the screen, for example only the image of the orange in this screen:

enter image description here

I found this artical, and tried to get the handle of this image but without success.

Edit: I need it not only for web pages, so Selenium and others are not an option.

zvi
  • 3,677
  • 2
  • 30
  • 48
  • 4
    `BitBlt` accepts four arguments that describe the source rectangle. The question is thus: How do you find the coordinates of the region of interest. [UI Automation](https://learn.microsoft.com/en-us/windows/win32/winauto/entry-uiauto-win32) is the only reasonable approach to try here, if the target application coöperates. A more robust implementation would probably just read the HTML code, parse out the URI of the image, and download the image instead. As a bonus this approach isn't susceptible to rendering artifacts. – IInspectable Jan 25 '22 at 08:35
  • @IInspectable that's my question - how can I get this rectangle coordinates? – zvi Jan 25 '22 at 08:48
  • 2
    There aren't any child windows so you cannot use a method that requires child windows. That leaves you pretty much with a single option: UI Automation (link to reference documentation in my previous comment). To get to the rectangle you're going to have to walk the accessible tree and find the accessible item you're interested in. This isn't something you can do in a handful of lines of code. Be prepared to write lots of code, tens and hundreds of lines. You are trying to solve a hard problem, that doesn't have a clear-cut solution. – IInspectable Jan 25 '22 at 09:35
  • Did you see the link at the end of my question? Looks like it was possible, but again it's not working for me know. – zvi Jan 25 '22 at 11:52
  • 1
    Yes, I did see that link. That implementation works for controls that have a dedicated child window. You are looking at the output of an HTML renderer, that doesn't use child windows. As explained in my previous comment, that precludes using this (or similar) schemes. – IInspectable Jan 25 '22 at 12:08
  • If you're only interested by web apps, it depends on the browser, but you could use Selenium (https://www.selenium.dev/) or Playwright (https://playwright.dev/) or other similar frameworks. – Simon Mourier Jan 25 '22 at 12:27
  • No, it's not for the web only. See my edit. – zvi Jan 25 '22 at 13:15
  • 3
    There is no generic solution in this case. While humans can pretty reliably identify images, text, or controls, this information is not in general present in the system. A black pixel could be part of an image, the color of text, or the border of a control. To the system it merely is a black pixel. To identify those elements you would have to gather circumstantial evidence. – IInspectable Jan 26 '22 at 10:13

0 Answers0