调整大小时不要缩放ImageBrush,请重复! [英] Don't scale ImageBrush while resizing, Repeat it!

查看:458
本文介绍了调整大小时不要缩放ImageBrush,请重复!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ImageBrush上有问题:

<Window ... >
    <Grid>
        <Grid.Background>
            <ImageBrush ImageSource="Controls\Images\notebook_paper_Line.jpg" TileMode="FlipX"
                        Viewport="0,0,1,0.09" />
        </Grid.Background>        
    </Grid>
</Window>

我想在用户调整窗口大小时重复图像.但是当前图像在用户调整窗口大小时会缩放. (请注意,图像尺寸很小,我使用TileModeViewport重复它,并且在调整大小时会出现问题!).

I want to repeat image while user resizing window. But currently image gets scale while user resizing window. (Note that image size is small and I use TileMode and Viewport to repeat it, And problem occurs while resizing it!).

任何XAML代码都很棒! :)

Any XAML code will be great! :)

对不起,英语不好!!!

推荐答案

默认情况下,TileBrush的视口为0,0,1,1,而ViewportUnits为RelativeToBoundingBox,这意味着0,0,1,1映射到整个目标大小(在本例中为Grid的边界).

By default, the Viewport for a TileBrush is 0,0,1,1 and the ViewportUnits are RelativeToBoundingBox, meaning that 0,0,1,1 maps to the entire destination size (in this case, the bounds of the Grid).

因此,如果要平铺ImageBrush,则需要调整视口.如果将视口设置为0,0,.5,.5,则应该看到以2 x 2切片的图像(因为每个切片的尺寸为Grid的50%x50%)或0,0,0.25, 0.1会产生4x10的拼贴,依此类推...

So if you want to tile an ImageBrush, you will want to adjust the Viewport. If you were to set the Viewport to 0,0,.5,.5, you should see images tiled 2 x 2 (since each tile will be 50%x50% the size of the Grid), or 0,0,0.25,0.1 would produce a 4x10 tiling, etc...

但是,这仍然不能防止图像重新缩放.因此,在您的情况下,您可能想要的是将视口设置为图像的大小,然后将ViewportUnits设置为Absolute而不是RelativeToBoundingBox.

However, that still doesn't prevent the image from rescaling. So in your case, what you probably want is to set the viewport to the size of your image, and set the ViewportUnits to Absolute instead of RelativeToBoundingBox.

在下面的xaml中,我有一个24x24像素的图像,因此我相应地设置了视口.这将在整个网格上重复平铺图像.如果调整了网格的大小,将显示更多的图块.

In the xaml below I have a 24x24 pixel image, so I set my viewport accordingly. This tiles the image repeatedly for the full size of the grid. If the grid is resized, more tiles will appear.

<ImageBrush ImageSource="Images\book_green.png" TileMode="FlipX" 
            Viewport="0,0,24,24" ViewportUnits="Absolute" />

我希望能帮上忙.

这篇关于调整大小时不要缩放ImageBrush,请重复!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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