Как найти физические координаты окна на рабочем столе и сохранить их как изображение ⇐ C#
Как найти физические координаты окна на рабочем столе и сохранить их как изображение
I have an application in C# that needs to use OCR to read labels and text controls.
The window I need to get a hold of is a real PITA to work with; I can't Spy++ or anything to just get handles to the controls because the application I need to read from has an embedded CEF (Chromium Embedded Framework) window widget. I can get the main window by title and get the handle, but it stops there; I can't get a handle to the CEF control or work with it in any way, I have to get a snapshot of the window (just the window, not the whole desktop in the background).
The issue I have is finding the Window's size and location on the desktop. My theory is that I could capture the image of the window I need to work with containing the CEF control, and use client relative coordinates to set up a RECT that I can pass to OCR for finding a text string there for me to work with.
I should just be able to get a handle to the main window, and get a RECT, and find out where it is and its size, for example:
// Get the window rectangle in screen coordinates RECT windowRect; GetWindowRect(hWnd, out windowRect); // Calculate the position of the client area in screen coordinates Point screenPoint = ...? ClientToScreen(hWnd, ref screenPoint); ? Or something like that, and it kind of works, but the image has some of the desktop in the background (it starts at top left of desktop, instead of the window I want), and the image is clipped, it's not wide or tall enough, like it has no idea what the size of the window is.
It makes me think I have to deal with screen scaling and DPI too, and on the system the application will run on, the screen's scaling is 1.5 and 144 DPI, the resolution is 2240 x 1400. I don't know what to make of that.
I have tried some tools to get client coordinates of the controls I'm interested in which are in the CEF control, but doing a simple translation of client to physical screen coordinates to get its X, Y and width, height to get an image, then feed the image into OCR to get the text just doesn't work out; the physical coordinates are close, but wrong.
Does anyone know how to get the position and size of a Window on the desktop, given its handle, so I can capture an image of just the application window? Then somehow it should just work if I have the relative client coordinates of controls on the window somewhere, from 0, 0 of the main application window, so I can capture images of controls on the screen given their relative X, Y locations and width and height, for OCR to extract text.
Thanks for any help!
I've tried everything I can think of for two weeks; locating the window handle, and trying to discover its location and size on the desktop to get an image. And then to translate the known client coordinates of controls within the window so I can image those, and feed the image to Tesseract to extract text from them (labels, text boxes, most of them read-only and greyed out).
Источник: https://stackoverflow.com/questions/780 ... -as-an-ima
I have an application in C# that needs to use OCR to read labels and text controls.
The window I need to get a hold of is a real PITA to work with; I can't Spy++ or anything to just get handles to the controls because the application I need to read from has an embedded CEF (Chromium Embedded Framework) window widget. I can get the main window by title and get the handle, but it stops there; I can't get a handle to the CEF control or work with it in any way, I have to get a snapshot of the window (just the window, not the whole desktop in the background).
The issue I have is finding the Window's size and location on the desktop. My theory is that I could capture the image of the window I need to work with containing the CEF control, and use client relative coordinates to set up a RECT that I can pass to OCR for finding a text string there for me to work with.
I should just be able to get a handle to the main window, and get a RECT, and find out where it is and its size, for example:
// Get the window rectangle in screen coordinates RECT windowRect; GetWindowRect(hWnd, out windowRect); // Calculate the position of the client area in screen coordinates Point screenPoint = ...? ClientToScreen(hWnd, ref screenPoint); ? Or something like that, and it kind of works, but the image has some of the desktop in the background (it starts at top left of desktop, instead of the window I want), and the image is clipped, it's not wide or tall enough, like it has no idea what the size of the window is.
It makes me think I have to deal with screen scaling and DPI too, and on the system the application will run on, the screen's scaling is 1.5 and 144 DPI, the resolution is 2240 x 1400. I don't know what to make of that.
I have tried some tools to get client coordinates of the controls I'm interested in which are in the CEF control, but doing a simple translation of client to physical screen coordinates to get its X, Y and width, height to get an image, then feed the image into OCR to get the text just doesn't work out; the physical coordinates are close, but wrong.
Does anyone know how to get the position and size of a Window on the desktop, given its handle, so I can capture an image of just the application window? Then somehow it should just work if I have the relative client coordinates of controls on the window somewhere, from 0, 0 of the main application window, so I can capture images of controls on the screen given their relative X, Y locations and width and height, for OCR to extract text.
Thanks for any help!
I've tried everything I can think of for two weeks; locating the window handle, and trying to discover its location and size on the desktop to get an image. And then to translate the known client coordinates of controls within the window so I can image those, and feed the image to Tesseract to extract text from them (labels, text boxes, most of them read-only and greyed out).
Источник: https://stackoverflow.com/questions/780 ... -as-an-ima
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение