1

我有一个带有全景图和一个按钮的简单页面,该按钮必须更改全景图的背景图片。原始图片是1200x800。如果我使用资源中的图片,一切都很好:

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;

但是如果我从独立存储中拍照:

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;

然后图片缩小到480x800

我做错了什么?或者它是来自MS的错误?

4

1 回答 1

1

看起来这是一个错误。该线程的一种解决方法:

我发现的一种解决方法是在 XAML 中设置一个具有所需大小的“默认”背景图像。如果我这样做,则更新 MainPage_Loaded 事件中的 Background 属性,新图像显示为与默认图像相同的大小。

在该线程的底部还有另一种解决方法,其中包含代码。

于 2011-11-03T18:08:01.093 回答