简体   繁体   English

在delphi画布中绘制图片的非矩形部分

[英]Drawing a non rectangular part of a picture in delphi canvas

任何人都可以共享示例代码在Delphi画布上绘制图片的非矩形部分吗?

Your question is pretty vague. 您的问题很模糊。 But I suspect what you are looking for is clipping regions. 但是我怀疑您正在寻找的是裁剪区域。 Read up on them. 阅读他们。 Set the clipping region on the target device to the shape you want, and then draw the image onto the device. 将目标设备上的剪切区域设置为所需的形状,然后将图像绘制到设备上。 Only the part of the image that would be within the clipping region will be drawn. 仅将绘制图像中位于裁剪区域内的部分。

You're looking for GDI paths. 您正在寻找GDI路径。 Start here , which explains what paths are in this context, and provides links on the left to explain the functionality available with them. 此处开始,它说明了这种情况下的路径,并在左侧提供了链接以说明它们可用的功能。

Google can turn up lots of examples of using paths in Delphi. Google可以提供许多在Delphi中使用路径的示例。 If you can't find them, post a comment back here and I'll see what I can turn up for you. 如果找不到,请在此处发表评论,我会为您提供帮助。

Canvas.Ellipse(0, 0, 10, 20); // not a rectangle

I use so called runlists for this feature (generalized shapes and blitting them). 我为此功能使用了所谓的运行列表(一般形状并对其进行blitting)。 I've seen them called warplists too. 我也看到过他们也称他们为经商。 A shape is encoded as a runlist by defining it as a set of horizontal lines, and each line is two integer values (skip n pixels,copy n pixels). 通过将形状定义为一组水平线,将形状编码为运行列表,并且每条线是两个整数值(跳过n个像素,复制n个像素)。

This means you can draw entire lines, leaving you with only "height" draw operations. 这意味着您可以绘制整条线,而仅进行“高度”绘制操作。

So a rectangle is defined (the first "skip" pixels from top level corner to the left corner (xorg,yorg). The rectangle is width_rect wide, and width_pixels goes a line further. width_pixels can be wider than the width of the picture (alignment bytes) 因此,定义了一个矩形(从最高角到左角的第一个“跳过”像素(xorg,yorg)。该矩形的width_rect宽,而width_pixels再往前一行。width_pixels可以比图片的宽度宽(对齐字节)

(yorg*width_pixels+xorg  , width_rect),
(width_pixels-width_rect , width_rect),
(width_pixels-width_rect , width_rect),
(width_pixels-width_rect , width_rect),
..
..

This way you can make your drawing routines pretty generic, and for simple, regular shapes (rects, circles) it takes only minor math to precalculate these lists. 这样,您就可以使绘图例程非常通用,并且对于简单的常规形状(矩形,圆形),只需很少的数学就可以预先计算这些列表。 It simplified my shape handling enormously. 它极大地简化了我的形状处理。

However I draw directly to bitmaps, not to canvasses, so I can't help with that part. 但是,我直接绘制到位图上,而不是画布上,所以我对此无能为力。 A primitive that efficiently draws a row, and a way to extract a row from a graphic should be enough. 有效绘制行的基元,以及从图形中提取行的方法就足够了。

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

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