C # GDI + Function Extension: Area Image Selection Function

Source: Internet
Author: User

Download the program/Files/xqzhao/DrawDragRect.rar in this article (the instance is a Form-based program written in C #. It displays a file opening dialog box to open an image file. After you select an image file, you can select a small area of the image, which will be separately displayed on another form .)

Program description
In most image processing applications (such as Adobe's Photoshop, Google's Picasa or Coral's Paint Shop Pro), they all need to be able to select a part of the image. You may want to enlarge the area of the image or select to further process the area.
For that application, most image processing software must support this function. When we write programs under the MFC framework, they use the DrawDragRect (…) of the CDC class (...). DrawDragRect (...) API.
Although almost all MFC APIs correspond to Win32 APIs, Microsoft does not provide a DrawDragRect (...) The Win32 API of the API. Therefore, this problem occurs under the. net Framework, because we cannot find such an API.
Therefore, when we use C # To write an image processing software, this problem becomes very prominent, and there is no DrawDragRect (...) Similar API to complete the image selection function. Moreover, a WIN32 api that can be called through pInvoke cannot be found. This article uses the C # language to implement DrawDragRect (...) API, you can easily call it in your program.

Implementation Details
The entire code is embedded in the CDrawDragRect. cs file and implemented in the CDrawDragRect class. If your program needs this function, you only need to integrate your program from the previous Form to the integration relationship of CDrawDragRect.
Public partial class MainForm: CDrawDragRect
// Form
{
...
// Other implementation details skipped for brevity
}
In addition, you also need to do one thing: In the CDrawDragRect class, the void DrawDragRect (MouseEventArgs e) function processes this function, when the mouse event OnMouseMove (MouseEventArgs e) occurs, respond to the action.
The DrawDragRect (MouseEventArgs e) function first creates four Windows regions:
RgnOld
RgnNew
RgnDiff
RgnDiffOld
RgnDiff records the difference between rgnOld and rgnNew ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.