Search code examples
windows-phone-7panorama-control

Panorama is shrinking background picture which is from Isolated Storage


I have a simple page with a panorama and a button which have to change a background picture of panorama. Originally picture is 1200x800. If I use a picture from Resources, everything is fine:

Uri uri = new Uri("Resources/Panorama.png", UriKind.Relative);
var bitmap2 = new BitmapImage(uri);

// here from debugging: bitmap2.CreateOptions == DelayCreation, bitmap2.PixelWidth == 0 and bitmap2.PixelHeight == 0

var lcBrush2 = new ImageBrush() {
    Stretch = Stretch.Fill,
    ImageSource = bitmap2 
};

panoMain.Background = lcBrush2;

but if I take a picture from Isolated Storage:

var picStream = ...getting a stream of file....;
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(picStream);

// here from debugging: bitmap.PixelWidth == 1200 and bitmap.PixelHeight == 800

var lcBrush = new ImageBrush() {
    Stretch = Stretch.Fill,
    ImageSource = bitmap 
};

panoMain.Background = lcBrush;

then the picture is shrinked to 480x800

What I am doing wrong? Or it is a bug from MS?


Solution

  • Looks like this is a bug. One workaround from that thread:

    One work-around I have found is to set a "default" Background Image in XAML which is of a desired size. If I do this, then update the Background property in my MainPage_Loaded event the new image shows as the same size as the default image.

    There is another workaround, with code, at the bottom of that thread.