简体   繁体   English

C#中的图像处理

[英]image processing in c#

before question think about for example photoshop. 问题之前,请考虑一下例如photoshop。 When you draw a rectangle on the picture.You can move it. 在图片上绘制矩形时,可以移动它。 And when you move it works very quickly and it doeasnt make some traces on the picture. 并且当您移动它时,它会非常快速地工作,并且不会在图片上留下痕迹。
So my question is, how to do that in c# application? 所以我的问题是,如何在C#应用程序中做到这一点?

When you are moving the rectangle, Photoshop doesn't put it in the image and then draw the image, instead the image is drawn without the rectangle, and the rectangle is drawn on top of that on the screen. 当您移动矩形时,Photoshop不会将其放在图像中然后再绘制图像,而是在不包含矩形的情况下绘制图像,并且在屏幕上的顶部绘制该矩形。 That way when you move the rectangle it can redraw the part of the image that previously was covered by the rectangle, and draw the rectangle at the new position. 这样,当您移动矩形时,它可以重新绘制以前由矩形覆盖的图像部分,并在新位置绘制矩形。

I think you're asking about selection rectangles (or other temporary shapes) on top of the document image. 我认为您是在询问文档图像上方的选择矩形(或其他临时形状)。 This effect is sometimes known as “rubber banding”, especially when drawing a line from one point to another (it stretches like a rubber band). 这种效果有时被称为“橡皮筋”,尤其是在从一个点到另一点画一条线时(它像橡皮筋一样伸展)。

Traditionally, this was done by using XOR drawing -- instead of overwriting the image with the selection shape, the colors in that area are inverted. 传统上,这是通过使用XOR绘图完成的-而不是用选择形状覆盖图像,而是反转该区域中的颜色。 Then, to remove the selection, it suffices to invert the colors again, returning to the same original image. 然后,要删除选择,只需再次反转颜色,即可返回相同的原始图像。 Today, graphics rendering is fast enough that such tricks are not usually necessary; 如今,图形渲染已经足够快,以至于通常不需要这些技巧。 it suffices to simply repaint that part of the window (without the rectangle). 只需重新绘制窗口的该部分即可(不包含矩形)。

Either way, it is important to recognize that the document image — the image the user is editing — is not the same as the window image, which is just a copy to be remade whenever necessary. 无论哪种方式,重要的是要认识到文档图像(用户正在编辑的图像)与窗口图像是不同的, 窗口图像只是在需要时可以重新制作的副本。 In the window, the document image is drawn and then selections, guide marks, and other such controls are drawn on top of it. 在窗口中,绘制文档图像,然后在其顶部绘制选择,引导标记和其他此类控件。

I'm not familiar with C#'s GUI facilities (and I understand there is more than one GUI framework you might be using), but it's probably got the usual structure of putting many "widgets", "views", or "controls" in the window (possibly nested inside each other). 我不熟悉C#的GUI设施(而且我知道您可能会使用多个GUI框架),但是它可能具有将许多“小部件”,“视图”或“控件”放入其中的通常结构。窗口(可能彼此嵌套)。 You can do a straightforward selection box — though not an optimally efficient one — by just putting an appropriately sized rectangle widget (with a solid border and a transparent background) on top of an image widget. 您可以通过将一个适当大小的矩形窗口小部件(带有实线边框和透明背景)放在图像窗口小部件上,来做一个简单的选择框(尽管不是最佳效率的选择框)。 This lets your GUI framework take care of the appropriate redrawing for you and is probably a good cheap way to start. 这使您的GUI框架可以为您进行适当的重绘,并且可能是一种不错的廉价入门方式。

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

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