如何在 TImage 中平铺图像?
如何在 Delphi 中平铺 TImage
中的图像?
为什么我需要它:我可以创建一个并将图像存储在那里,而不是在运行时创建更多 TImage,因为我知道它将“适合”直到达到 TImage 的高度和宽度。
请提出任何想法来做到这一点。
谢谢你!
编辑:请注意,我不是要求拉伸图像,而是通过重复图像来填充画布。
How do I tile an image in a TImage
in Delphi?
Why I need it: Instead of creating more TImages at runtime, I could create one and store my image there knowing that it will be 'fit' until it reaches TImage's height and width.
Please suggest any ideas to do this.
Thank you!
EDIT: Please note, I'm not asking for streching the image, but filling the canvas by repeating the image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
假设您的图像是位图并加载到 TImage 中,您可以使用以下
一些注释:
如果在给图像添加标题后保存图像,您将保存带标题的版本而不是原始版本。
Image1.Canvas 和 Image1.Picture.Bitmap.Canvas 是相同的,这就是为什么您需要在画布上绘画之前调整位图的大小。
如果您尝试将 TImage 中的位图分配给画笔,而不先将其分配给另一个位图对象,就像这样 Image1.Canvas.Brush.Bitmap := Image1.Picture.Bitmap 你会得到一个异常“not足够的存储空间”。
Assuming your image is a bitmap and loaded into the TImage you can use the following
Some notes:
If you save the image after titling it you will save the titled version not the original.
Image1.Canvas and Image1.Picture.Bitmap.Canvas are one and the same, that's why you need to resize the bitmap before painting on the canvas.
If you try and assign the bitmap in the TImage to the brush without assigning it to another bitmap object first like so Image1.Canvas.Brush.Bitmap := Image1.Picture.Bitmap you get an exception "not enough storage".
Delphi 安装附带一个名为“Bitmap”的 Demo(您可以在 Help 目录中找到该项目)。
它使用以下方法来绘制平铺图像:
希望有帮助!
Delphi installation comes with a Demo named 'Bitmap' (you can find the project in Help dir.).
It uses the following method to draw a tiled image:
Hope that helps!
您可以将
canvas.brush.bitmap :=
设置为图块的图像。 然后canvas.fillrect(canvas.cliprect)
使用所选平铺图像平铺整个画布。 我已经很长时间没有这样做了,我无法检查这是否真的是现在在 Delphi 中完成的,但我很确定这就是你想要的。You could set the
canvas.brush.bitmap :=
to the image of the tile. thencanvas.fillrect(canvas.cliprect)
to tile the whole canvas with the selected tile image. I haven't done it in a long time and I am not able to check if this is really how it's done in Delphi right now, but I am pretty sure this is what you're after.以下是我使用的函数,采用现有的 TImage 组件并将其平铺在目标画布上:
因为 tLabel 公开画布,所以您可以执行如下操作:
The following is the function that I have used, taking an existing TImage component and tiling it over a target canvas:
Because a tLabel exposes a canvas, you can do tricks like the following:
你说的“装修”是指“铺瓷砖”吗?
据我所知,TImage 不支持开箱即用。 您必须以重复模式在 TImage 的画布上手动绘制图片。
By "fitting" do you mean "tiling"?
As far as I know, TImage does not support this out of the box. You'd have to manually draw your picture on the TImage's Canvas in a repeating pattern.