当前位置:   article > 正文

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

c#wpf 图片实时加载
  1. //Createsource BitmapImagemyBitmapImage= new BitmapImage();
  2. //BitmapImage.UriSourcemustbeinaBeginInit/EndInitblock
  3. myBitmapImage.BeginInit(); myBitmapImage.UriSource= new
  4. Uri(str,UriKind.Absolute);
  5. //Tosavesignificantapplicationmemory,settheDecodePixelWid// Create source
  6. BitmapImage myBitmapImage = new BitmapImage();
  7. // BitmapImage.UriSource must be in a BeginInit/EndInit block
  8. myBitmapImage.BeginInit();
  9. myBitmapImage.UriSource = new Uri(str, UriKind.Absolute);
  10. // To save significant application memory, set the DecodePixelWidth or
  11. // DecodePixelHeight of the BitmapImage value of the image source to the desired
  12. // height or width of the rendered image. If you don't do this, the application will
  13. // cache the image as though it were rendered as its normal size rather then just
  14. // the size that is displayed.
  15. // Note: In order to preserve aspect ratio, set DecodePixelWidth
  16. // or DecodePixelHeight but not both.
  17. myBitmapImage.DecodePixelWidth = 2048;
  18. myBitmapImage.EndInit();
  19. //set image source
  20. Image img = new Image();
  21. 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;

转载于:https://www.cnblogs.com/leelike/archive/2012/03/27/2420149.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/732035
推荐阅读
相关标签
  

闽ICP备14008679号