BitmapImage tempBitmap = new BitmapImage(onlineImageLocation);
相当简单的代码。OnlineImageLocation 指的是http://dantonybrown.com/brownsoft/SweepyCleaner.png
但在构建位图图像后不包含填充字段。甚至 PixelWidth 和 PixelHeight 都是 0。
有任何想法吗?
丹尼
BitmapImage tempBitmap = new BitmapImage(onlineImageLocation);
相当简单的代码。OnlineImageLocation 指的是http://dantonybrown.com/brownsoft/SweepyCleaner.png
但在构建位图图像后不包含填充字段。甚至 PixelWidth 和 PixelHeight 都是 0。
有任何想法吗?
丹尼
For instance like this?
BitmapImage bmpImage = new BitmapImage(new Uri("http://dantonybrown.com/brownsoft/SweepyCleaner.png"));
MessageBox.Show(bmpImage.PixelWidth.ToString());
That makes perfect sense. The image is loaded on demand, and on the background. You have multiple options here:
Assign the BitmapImage to an Image control. You can access the properties after the ImageLoaded event occured:
BitmapImage bmpImage = new BitmapImage(new Uri("http://dantonybrown.com/brownsoft/SweepyCleaner.png"));
bmpImage.ImageOpened += (sender, args) => Dispatcher.BeginInvoke(() => MessageBox.Show(
bmpImage.PixelWidth.ToString(CultureInfo.InvariantCulture)));
imageCtrl.Source = bmpImage;
Load the BitmapImage with CreateOptions.None. This will still load the image in the background, but you don't have to assign the image to a control before it starts loading:
BitmapImage bmpImage = new BitmapImage(new Uri("http://dantonybrown.com/brownsoft/SweepyCleaner.png"))
{CreateOptions = BitmapCreateOptions.None};
bmpImage.ImageOpened += (sender, args) => Dispatcher.BeginInvoke(() => MessageBox.Show(
bmpImage.PixelWidth.ToString(CultureInfo.InvariantCulture)));