我有一个简单的页面,有一个全景和一个按钮,必须更改全景的背景图片。原本图片是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;
然后将图片收缩到480×800
我我做错了吗?或者它是来自MS的错误?
你可以使用相同的画笔加载代码加载资源从文件?您可能需要将资源设置为CopyToOutput的属性 – AlSki
我不明白你的意思。 – giacoder
您可以使用bitmap = new BitmapImage(uri);在我想要的代码 – AlSki