2

我正在使用 C# 和 .NET Compact Framework 开发 Windows Mobile 应用程序。

我想用较小的图像填充位图。为了填充这个新的位图,我想水平和垂直重复图像,直到位图完全填充。

我怎样才能做到这一点?

谢谢!

4

3 回答 3

1

在您的目标上使用Graphics.FromImage来获取一个 Graphics 对象,然后在生成的 Graphics 对象上使用 DrawImage 方法在您的图块中进行绘制。根据瓦片的大小和目标位图(即偏移 x、y 的瓦片大小并重复),根据需要对每行和列重复。

于 2009-11-16T20:27:20.667 回答
0

试试这个:

for(int y = 0; y < outputBitmap.Height; y++) {
    for(int x = 0; x < outputBitmap.Width; x++) {
        int ix = x % inputBitmap.Width;
        int iy = y % inputBitmap.Height;
        outputBitmap.SetPixel(x, y, inputBitmap.GetPixel(ix, iy));
    }
}
于 2009-11-16T18:29:10.280 回答
0

ATextureBrush可以轻松地在整个表面上重复图像。这比手动跨行/列平铺图像要容易得多。

只需创建TextureBrush然后使用它来填充一个矩形。它会自动平铺图像以填充矩形。

using (TextureBrush brush = new TextureBrush(yourImage, WrapMode.Tile))
{
    using (Graphics g = Graphics.FromImage(destImage))
    {
        g.FillRectangle(brush, 0, 0, destImage.Width, destImage.Height);
    }
}

上面的代码来自类似的答案:https ://stackoverflow.com/a/2675327/1145177

于 2014-06-12T04:02:18.177 回答