问题平铺图像开始在C#中使用的TextureBrush不同的高度 [英] Problem in tiling image starting at different height using TextureBrush in C#

查看:1146
本文介绍了问题平铺图像开始在C#中使用的TextureBrush不同的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在尺寸的矩形区域平铺图像(16×16)宽度= 1000,高度= 16。

I am trying to tile an image(16x16) over a Rectangle area of dimensions width=1000, height=16 using TextureBrush to get a strip like UI.

 Rectangle myIconDrawingRectangle = new Rectangle(x, y, 1000, 16);
 using (TextureBrush brush = new TextureBrush(myIcon, WrapMode.Tile))
 {
    e.Graphics.FillRectangle(brush, myIconDrawingRectangle );
 }

当我将x = 0战平,Y = 0平铺发生,因为预计首发从(0,0)。

When I draw with x=0, y=0 tiling happens as expected starting from (0,0).

当我将x = 0战平,Y = 50瓦片开始于(0.50),但画矩形不启动图象的开始。它开始与图像的裁剪部,然后重复。

When I draw with x=0, y=50 tiling starts at (0,50) but the the painting rectangle does not start with the start of the image. It starts with cropped portion of the image and then repeats.

如何解决这个

PS:我不想瓷砖它手工反复循环结束的DrawImage。

P.S: I do not want to tile it manually looping repeatedly over DrawImage.

推荐答案

要确保矩形的起点与图像的起点开始,我们必须使用转换,如下面的代码。

To ensure that start of the rectangle starts with start of the image we have use transforms as shown in below code.

Rectangle myIconDrawingRectangle = new Rectangle(x, y, 1000, 16);
using (TextureBrush brush = new TextureBrush(myIcon, WrapMode.Tile))
{
    brush.TranslateTransform(x,y);
    e.Graphics.FillRectangle(brush, myIconDrawingRectangle);
}



我发现这个的链接很有帮助。这就解释了有关的刷子和详细变换。

I found this link helpful. This explains about brushes and transforms in detail.

这篇关于问题平铺图像开始在C#中使用的TextureBrush不同的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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