Carlos G.
Carlos G.

Reputation: 4634

Why is my ImageBrush scaling a Tiled image?

I have the following ImageBrush declaration that I want to use to draw the background of a window.

     <ImageBrush x:Key="Fondo" 
      ImageSource="Fondo.png"        
      Viewport="0,0,0.1,0.1" TileMode="Tile"/>

If I set it using a StaticResource binding to the Background property of the Window the brush is rendered correctly, but the image is being scaled. This is a behavior I don't want, I want the application to use the image at its native resolution and repeat it as necessary to fill the window background, without any kind of scaling. I don't know what I'm doing wrong.

The image I'm using is 200px wide and 200px tall. The viewport values I have there were guessed, but it was not working before I did that.

Thanks for any help

EDIT: Fixed a contradiction in the question

Upvotes: 1

Views: 4343

Answers (2)

Carlos G.
Carlos G.

Reputation: 4634

Found the problem. The image was a png that was designed for a 72 dpi resolution. Therefore WPF was scaling it to match the standard 96 dpi resolution. The problem was not with the code.

Upvotes: 5

Alex
Alex

Reputation: 332

If you know the resolution of the source image, you can set the ViewBox and ViewPort values as pixels. Set ViewBoxUnits and ViewPortUnits to absolute and you should be able to achieve the effect that you want.

<ImageBrush ViewBox="0,0,200,200" 
ViewBoxUnits="Absolute"
ViewPort="0,0,200,200"
ViewPortUnits="Absolute" />

Upvotes: 2

Related Questions