tags:

views:

33

answers:

1

Hello everyone,

Here is a code.

var image = new BitmapImage(new Uri(@"pack://application:,,,/Images/background.png",
          UriKind.RelativeOrAbsolute));

   var backgroundBrush = new ImageBrush()
   {
    ImageSource = image,
    Viewport = new Rect(0, 0, image.PixelWidth / ActualWidth,
          image.PixelHeight / ActualHeight),
    TileMode = TileMode.Tile,
    Stretch  = Stretch.None,
   };

   // Set it for the main window.
   Background = backgroundBrush;

It works just fine on my PC with XPSP3 and .Net 4.0. But when I run the same sample on Eee PC T91MT with Windows 7 Home Premium it fails. No exceptions, but nothing is drawn (solid color brushes ARE drawn if used instead, though). I thought it could be the result of limited resources, but on Viliv S5, that has about the same specs it works fine too.

Any ideas?

Thanks!


UPDATE

The root of the problem is Viewport's rect. Since the bitmap has twice window's size by X, the rect is (0, 0, 2, 1). So, on power computer with XPSP3, the left half of the image is drawn. But on Eee PC it causes a problem with visualization.

+1  A: 

The answer is just normalizing Viewport rectangle. E.g. instead of (0,0,2,1) I had to set it as (0,0,1,0.5).

I'm not sure, but it looks like WPF just transmit rect values (after some transformation) into a D3D driver, which is (or is not) able to handle it the right way. So, non-normalized rect Viewport works on GeForce-based machine but does not on Eee PC with it's integrated video's driver.

noober