简体   繁体   中英

Draw rectangular selection and get corresponding image in WPF c#

I need to write a text recognition (from image) application. The main idea is that while my application is running, I may have the need to transform some text of an image into manageble text. So, in this case with the mouse I need to draw a square around the area that i need to capture and the software must convert the content of the extracted picture into text.

I solved the problem of image recognition. I also find a very easy way to capture from screen.

What I need to do now is be able to select with the mouse the interesting area that is over an other running opplication (for example over a webpage or over an image opened in Paint). That must be like the screencapture on windows7, you create a selection of the screen and this is saved like a picture.

By looking around, I didn't find anything and I don't knwo where to start.

Many thanks

You can achieve that using either a 'tricky' easy way or a real but difficult approach.

The tricky way

Screen Recorder applications usually use this approach: Whenever user wants to select an area, you display a full screen border less Window with 0% opacity, then user attempts to select the screen area, and he is actually selecting your Window area, so you can receive mouse events and display/draw a rectangular shape to show the selection area to the user.

In this approach, the program needs to know when to display the Window and when to hide it. This can be done by for example defining Hotkeys for capturing:

  • Program registers a hot key using RegisterHotKey to Windows.
  • User presses and holds that hot key
  • Program displays the tricky Window
  • User selects the interested area, program receives that area using mouse events of the tricky Window
  • User released the hot key and program hides the Tricky window.

The real way

Using this way, you need to set a message hook in order to receive mouse and keyboard events while user is interacting with desktop not your program. This is not an easy to accomplish approach and I recommend you the first one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM