如何可以擦除从的TCanvas了一张照片? [英] How can erase a single Picture from a TCanvas?

查看:187
本文介绍了如何可以擦除从的TCanvas了一张照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的形式,其中包含一个画布的透明面板(我认为它的实现并不重要位置;有人告诉我,否则)。我画很多位图上这个画布,用BYA:

I have in my form, a Transparent Panel which contains a Canvas (I think its implementation is not really important here; someone tell me otherwise). I'm drawing many Bitmaps on this Canvas, bya using:

Panel.Canvas.Draw(Image.Left, Image.Top, Image.Picture.Bitmap, Opacity);
//Image is a TImage instance
//Opacity is an integer 0..255

但是当我做了一些的TImage变化,像redimensioning或周围的形式移动,我redaw其在面板的图片。这里的问题是,旧的定位的图像保持在画布上。
现在我的问题:有一种方法来擦除画布上的一个位图?如果是的话,那会是什么?如果没有,有一种方法来清除所有画布的内容是什么?这样一来,我可以重绘保持图片。

But when I do some change in the TImage, like redimensioning or moving around the form, I redaw its Picture in the panel. The issue here is that the old positioned image remains on the canvas. Now my question: There is a way to erase a single Bitmap on the Canvas? If so, what it would be? If not, there is a way to erase all the canvas's contents? This way I could redraw the remain pictures.

编辑:

最后,我的问题是我用的透明面板上。它的油漆方法是bogous并没有失效的画布删除其中的控制。问题解决了,反正。我应该怎么做的问题?

At the end, my problem were on the Transparent Panel I was using. Its Paintmethod was bogous and did not invalidate its canvas to erase the controls on it. Problem solved, anyway. What should I do with the question?

推荐答案

不是真的,因为画布不跟踪不同的图像。

Not really, because the canvas doesn't keep track of distinct images.

不过,你可以很容易地清除只需在它绘图画布的任何部分。结果
这将允许你重绘所有剩余的图片。

However, you can easily "clear" any part of your canvas simply by drawing over it.
This will allow you to redraw all remaining pictures.

这可能不过是相当的时间,如果有很多照片和用户忙拖拽一张照片消耗;因为这将导致大量的重画了运动图像的每一个微小的位置变化。

This could however be quite time consuming if there are many pictures and a user is busy dragging a single picture around; as this would result in a lot of redrawing for each slight position change of the moving image.

一个选项是与XOR面具画了积极的形象,而它的被调整。然后,它可以通过简单地在同一个XOR掩模的相同位置再次重新绘制被擦除。这具有的缺点是,颜色变得失真,但它是非常有效的。

One option is to draw the "active" image with an XOR mask while it's being adjusted. Then it can be erased by simply redrawing in the same position with an XOR mask again. This has the disadvantage that colours become distorted, but it is very efficient.

另一个选择是让你在绘制之前,你打算绘制活动画面的画布的一部分的副本。然后,你有一个简单的机制,在正确的位置重画复制删除新的图片。

Another option is to make a copy of part of the canvas where you intend drawing the active picture before you draw. Then you have a simple mechanism to erase the new picture by redrawing the copy in the correct position.

和我怎么能画过它,因为我有没有背景?有某种透明刷?

And how could I draw over it since I have no background? There is some kind of Transparent brush?

假设你要绘制和移动图像(可能是一个蓝色矩形20×60):

Suppose you want to draw and move a picture (perhaps a blue rectangle 20x60):


  • 让我们假设你开始一个空白的画布, clWhite 背景。

  • 的初始位置是(25,75),所以:

  • (A)首先,在(25,75)在你的画布复制20×60矩形。

  • 副本当然会全白,但那是你的背景看起来完全像什么。

  • 现在,在该位置绘制矩形。

  • Let's assume you start with a blank Canvas, clWhite background.
  • The initial position is (25,75), so:
  • (A) First copy the 20x60 Rect at (25,75) on your Canvas.
  • The copy will of course be entirely white, but that is exactly what your background looked like.
  • Now draw your rectangle at that position.

酷,第一位完成。现在你想的矩形移动到(40,90):

Cool, first bit done. now you want to move the rectangle to (40,90):


  • 在(25,75)画出你复印的图像。 NB 无透明度可言!你想恢复你的画布状态的(A),您绘制的蓝色矩形前。

  • 在(40,90)复制20×60矩形。 (再次将完全白色)

  • 在(40,90),把你的蓝色矩形。

  • Draw your copied image at (25,75). NB No transparency at all! You want to restore your Canvas to the state at (A), before you drew the blue rectangle.
  • Copy the 20x60 Rect at (40,90). (Again it will be entirely White)
  • Draw your blue rectangle at (40,90).

好了,到目前为止好,但我们的副本总是白色。因此,让我们添加第二个矩形。 (这一次红色和80x10)。

Ok, so far so good, but our copies are always White. So let's add a second rectangle. (This time red and 80x10.)


  • 我们会放弃我们当前的副本,因为我们不再需要移动的蓝色矩形。

  • 我们要放置在(45,95)的红色矩形,使其重叠蓝色的。

  • (B)是在复制80x10矩形(45,95)

  • 注意,副本的这段时间部分是蓝色的,其余是白色的。

  • 现在,绘制红色矩形在(45,95)

  • We'll discard our current copy because we no longer want to move the blue rectangle.
  • We want to place the red rectangle at (45,95), so it overlaps the blue.
  • (B) Copy the 80x10 Rect at (45,95)
  • Note, this time part of the copy is blue, the rest is white.
  • Now draw the red rectangle at (45,95)

作为最后的步骤,让红色矩形的大小减小到5×5

As a final step, lets decrease the size of the red rectangle to 5x5:


  • 把你复制的图像(45,95)。 NB 同样这是非常重要的,我们的使用的透明度,因为我们正在努力,我们提请红色矩形恢复图像的部分回是什么样子在(B)

  • 的5x5的矩形复制处(45,95)

  • 绘制较小的红色矩形。

  • Draw your copied image (45,95). NB Again It's very important that we do not use transparency, because we're trying to restore the portion of the image where we drew the red rectangle back to what it looked like in (B).
  • Copy the 5x5 Rect at (45,95)
  • Draw the smaller red rectangle.

这是一个简单的冲洗重复的过程。由于恰巧,这是Windows用于绘制鼠标光标,因为它移动相同的技术。

This is a simple rinse-repeat process. As it so happens, this is the same technique used by Windows to draw your mouse cursor as it moves.

边注:如果您正在绘制的图像,是一个不规则的形状,它无关紧要。只要您的备份矩形完全覆盖你绘制图像,这种技术的工作原理。

Side note: If the image you're drawing is an irregular shape, it doesn't matter. Provided your backup rectangle fully covers the image you're drawing, this technique works.

这篇关于如何可以擦除从的TCanvas了一张照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆