Windows Vista Forums

ImageBrush Bugs?

  1. #1


    HolaMan Guest

    ImageBrush Bugs?

    Hi all

    I use imagebrush to fill a rectangle
    But I found the image will stretch a little for special size.
    <StackPanel Background="Red">
    <Rectangle Width="500" Height="300" x:Name="r">
    <Rectangle.Fill>
    <ImageBrush x:Name="imgBrush" ImageSource="d:\\op.png"



    Stretch="None"
    Viewport="0,0,27,27" ViewportUnits="Absolute"
    AlignmentX="Left" AlignmentY="Top"/>
    </Rectangle.Fill>
    </Rectangle>
    </StackPanel>

    What I test is use two different size png file with alpha channel.
    One is 216x108, the other one is 248x124.
    But I found 248x124 is fine (mean didn't stretch), and the other is
    stretch a little.
    I use viewport "0,0,27,27" to check if stretch or not.
    Is there any ideas for the strange result?

    Thanks,

    HolaMan


      My System SpecsSystem Spec

  2. #2


    Adam Smith [MS] Guest

    Re: ImageBrush Bugs?

    One thing to check is whether one of the .pngs has a different DPI than the
    other. You can check this by right-clicking on the file and looking at the
    properties dialog, then the summary tab (click the "Advanced>>>" button if
    you need to on that tab).

    -Adam Smith [MS]

    "HolaMan" <reality.chang@gmail.com> wrote in message
    news:1144813198.091445.226410@z34g2000cwc.googlegroups.com...
    > Hi all
    >
    > I use imagebrush to fill a rectangle
    > But I found the image will stretch a little for special size.
    > <StackPanel Background="Red">
    > <Rectangle Width="500" Height="300" x:Name="r">
    > <Rectangle.Fill>
    > <ImageBrush x:Name="imgBrush" ImageSource="d:\\op.png"
    >
    > Stretch="None"
    > Viewport="0,0,27,27" ViewportUnits="Absolute"
    > AlignmentX="Left" AlignmentY="Top"/>
    > </Rectangle.Fill>
    > </Rectangle>
    > </StackPanel>
    >
    > What I test is use two different size png file with alpha channel.
    > One is 216x108, the other one is 248x124.
    > But I found 248x124 is fine (mean didn't stretch), and the other is
    > stretch a little.
    > I use viewport "0,0,27,27" to check if stretch or not.
    > Is there any ideas for the strange result?
    >
    > Thanks,
    >
    > HolaMan
    >




      My System SpecsSystem Spec

  3. #3


    HolaMan Guest

    Re: ImageBrush Bugs?

    Thanks for you reply
    I have checked the pngs and you are right.
    They have different DPI value, one is 72 and the other is 96.

    :which DPI will result the right size of ImageBrush? seems 96
    Thank you.


      My System SpecsSystem Spec

  4. #4


    Adam Smith [MS] Guest

    Re: ImageBrush Bugs?

    > which DPI will result in the right size of ImageBrush

    Well, that's sort of a trick question - both DPIs can result in the
    "correct" size. If, however, you always want the size WPF
    reports/measures/etc to be the same as the pixel dimensions, then yes, 96
    DPI will produce that mapping. When you look at the Width or Height of a
    Bitmap in Avalon, this value is the width (or height) in pixels of the
    Bitmap divided by the DPI * 96, because all of WPF's units are 96'ths of an
    inch. This is why a bitmap with 96DPI measures at its pixel dimensions,
    because the mapping is identity.

    Note that a 72x72 pixel bitmap at 72 DPI is really 1 inch by 1 inch and a
    96x96 pixel bitmap at 96 DPI is *also* 1 inch by 1 inch, which is why they
    will measure the same in WPF even though they have different pixel
    dimensions.

    -Adam Smith [MS]


    "HolaMan" <reality.chang@gmail.com> wrote in message
    news:1145263146.871828.266720@e56g2000cwe.googlegroups.com...
    > Thanks for you reply
    > I have checked the pngs and you are right.
    > They have different DPI value, one is 72 and the other is 96.
    >
    > :which DPI will result the right size of ImageBrush? seems 96
    > Thank you.
    >




      My System SpecsSystem Spec

ImageBrush Bugs?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding an ImageBrush Problem star-italia .NET General 5 13 Jun 2008
Creating an BitmapImage from an ImageBrush? scott.browse@gmail.com Avalon 0 13 Aug 2007
ImageBrush & 3D John Avalon 1 24 Oct 2006
ImageBrush Tiling Kevin Hoffman Avalon 1 03 Mar 2006
ImageBrush TileMode not working? Corrado Cavalli [MVP] Avalon 3 10 Jan 2006