在C#中重复图像 [英] Repeat image in C#
问题描述
我有一定的图案的图像。我如何使用GDI重复它在另一个形象?
是否有任何方法来做到这一点在GDI?
I have an image with a certain pattern. How do I repeat it in another image using GDI? Is there any method to do it in GDI?
推荐答案
在C#中,你可以创建一个的TextureBrush那会瓷砖无论你使用它,然后用它填充区域图像。像这样的东西(即填满整个图像的例子)...
In C#, you can create a TextureBrush that'll tile your image wherever you use it, and then fill an area with it. Something like this (an example that fills the whole image)...
// Use `using` blocks for GDI objects you create, so they'll be released
// quickly when you're done with them.
using (TextureBrush brush = new TextureBrush(yourImage, WrapMode.Tile))
using (Graphics g = Graphics.FromImage(destImage))
{
// Do your painting in here
g.FillRectangle(brush, 0, 0, destImage.Width, destImage.Height);
}
请注意,如果你想在图像是如何平铺一些控制,你' 。重新将需要学习一些关于转换
Note, if you want some control over how the image is tiled, you're going to need to learn a bit about transforms.
我几乎忘了(其实我做了一个有点忘了):你需要导入 System.Drawing中
(为图形
和的TextureBrush
)和 System.Drawing.Drawing2D
(为 WrapMode
),以便上面的代码工作原样。
I almost forgot (actually I did forget for a bit): You'll need to import System.Drawing
(for Graphics
and TextureBrush
) and System.Drawing.Drawing2D
(for WrapMode
) in order for the code above to work as is.
这篇关于在C#中重复图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!