简体   繁体   English

C# WinForms - 图片/图像框选择 - 像 MS Paint

[英]C# WinForms - picture / image box selection - like MS Paint

I'm working on a small project that involves me loading an image into a picture box within a windows form.我正在做一个小项目,该项目涉及将图像加载到 Windows 窗体中的图片框中。 I then need to be able to select and area of this image, and "crop" to that size - kind of like you can do in MS Paint.然后我需要能够选择该图像的区域,并将其“裁剪”到该大小 - 就像您可以在 MS Paint 中所做的那样。

I was just wondering if anyone knew of any sample code available to help me start this?我只是想知道是否有人知道任何可以帮助我开始的示例代码?

I've had luck with this code:我对这段代码很幸运:

Cropping Images 裁剪图像

It is a pretty simple problem.这是一个非常简单的问题。 You need to handle MouseDown, MouseUp, and keep track of when you start and stop dragging your selection rectangle.您需要处理 MouseDown、MouseUp,并跟踪开始和停止拖动选择矩形的时间。 Now that you have done that you already have the selection rect, so just use that to take a portion of the whole image.现在您已经完成了选择矩形,所以只需使用它来获取整个图像的一部分。 If you are displaying a scaled version just find the ratio between the control's dimensions and the dimensions of the image.如果您正在显示缩放版本,只需找到控件尺寸与图像尺寸之间的比率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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