Experience10  Creative, Develop, UX, Wireframe, Productivity

WP7上的Image使用技巧

部分翻译摘录自swick的blog

如果经常开发App,WP7上的Image显示造成的内存增大问题一定会遇到,以下是一些使用技巧帮助减少这类情况的发生:

JPG vs. PNG

如果不是必须要使用透明图片,JPG是最好的选择,WP7的JPG编码速度要大大快于PNG

Resource vs. Content

将图片(或其它种类资源)用何种类型进行XAP编译绑定的时候。Resource和Content有很大的不同,Resource会绑定到Dll之中,在显示图像时很快,但加载整个XAP包时很慢。而Content会使得加载XAP应用时很快,但加载图像时稍慢一些。根据情况选用,使用方法:

Content: <Image Source=”/ImagesAsContent/smiley1.png”/>
Resource: <Image Source=”..\ImagesAsResource\smiley3.png”/>

Async vs. Sync 异步或同步加载图片

BitmapImage.UriSource = uriSource; // 从URI中读取,异步加载

BitmapImage.SetSource(stream);     // 从流中读取,同步加载

图片缓存

如果内存没有被回收,可以考虑主动释放:

BitmapImage bitmapImage = image.Source as BitmapImage;

bitmapImage.UriSource = null;

image.Source = null;

自定义编码

如果所需图片尺寸不需要很大,可以将来源进行重编码,使用PictureDecoder API可完成这个操作如下:

image.Source = PictureDecoder.DecodeJpeg(jpgStream, 192, 256);

This entry was written by allan, posted on May 3, 2011 at 11:17 am, filed under WP7. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

Timeline

Have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.


Copyright 2010 Experience10.com
Designed by Allan