wp7蛋疼的90M内存限制,优化图片使用内存(4)[解决]
经过研究我现在解决了 wp7下 超长图片 超过2000长度的图片加载
使用以下技术点
1. 使用 LazyListBox 参考: http://blogs.msdn.com/b/ptorr/archive/2010/10/12/procrastination-ftw-lazylistbox-should-improve-your-scrolling-performance-and-responsiveness.aspx
2.使用 WriteableBitmap 参考:http://www.cnblogs.com/magicboy110/archive/2010/12/13/1905065.html
3.使用 WriteableBitmapEx 参考:http://writeablebitmapex.codeplex.com/
首先先拆解数据内容
完成图
代码如下
//图片高度 double pixelHeight = double.Parse(jobj["height"].ToString()); //图片宽度 double pixelWidth = double.Parse(jobj["width"].ToString()); var uriStr = jobj["img"].ToString(); /********* * 计算缩放 *********/ if (pixelWidth > 400) { pixelHeight = pixelHeight * 400 / pixelWidth; } /*********************************** * * 图片高度大于1000 拆解成 图片列表 * * *********************************/ if (pixelHeight > 1000) { WriteableBitmap wb = new WriteableBitmap((int)pixelWidth, (int)pixelHeight); Uri uri = new Uri(uriStr); StreamResourceInfo sri = Application.GetResourceStream(uri); System.Windows.Media.Imaging.Extensions.LoadJpeg(wb, sri.Stream); WriteableBitmap Source; for (int iii = 0; iii * 1000 < pixelHeight; iii++) { LazyListBoxItemVo iivo = new LazyListBoxItemVo(); iivo.indexNum = index; if ((iii + 1) * 1000 > pixelHeight) { var h = pixelHeight - (iii * 1000); iivo.imgHeight = h; Source = wb.Crop(0, iii * 1000, 400, h); } else { Source = wb.Crop(0, iii * 1000, 400, 1000); } iivo.imgWidth = pixelWidth; iivo.imgSource = Source; iivo.ContentPanelVisibility = Visibility.Visible; LazyList.Add(iivo); } }//展示原图 else { ........................ }
优化后