您的位置:首页 > 其它

WPF Image动态加载图片终极办法

2012-03-27 20:58 363 查看
//Createsource BitmapImagemyBitmapImage= new BitmapImage();
//BitmapImage.UriSourcemustbeinaBeginInit/EndInitblock
myBitmapImage.BeginInit(); myBitmapImage.UriSource= new
Uri(str,UriKind.Absolute);
//Tosavesignificantapplicationmemory,settheDecodePixelWid

// Create source
BitmapImage myBitmapImage = new BitmapImage();

// BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(str, UriKind.Absolute);

// To save significant application memory, set the DecodePixelWidth or
// DecodePixelHeight of the BitmapImage value of the image source to the desired
// height or width of the rendered image. If you don't do this, the application will
// cache the image as though it were rendered as its normal size rather then just
// the size that is displayed.
// Note: In order to preserve aspect ratio, set DecodePixelWidth
// or DecodePixelHeight but not both.
myBitmapImage.DecodePixelWidth = 2048;
myBitmapImage.EndInit();
//set image source

Image img = new Image();
img.Source = myBitmapImage;


// Create source
BitmapImage myBitmapImage = new BitmapImage();

// BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(str, UriKind.Absolute);

// To save significant application memory, set the DecodePixelWidth or
// DecodePixelHeight of the BitmapImage value of the image source to the desired
// height or width of the rendered image. If you don't do this, the application will
// cache the image as though it were rendered as its normal size rather then just
// the size that is displayed.
// Note: In order to preserve aspect ratio, set DecodePixelWidth
// or DecodePixelHeight but not both.
myBitmapImage.DecodePixelWidth = 2048;
myBitmapImage.EndInit();
//set image source

Image img = new Image();
img.Source = myBitmapImage;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: