WP7 working with Images: Content vs Resource build action
来源:互联网 发布:2016nba总决赛每场数据 编辑:程序博客网 时间:2024/06/05 07:27
by WindowsPhoneGeek
Generally there are two ways to include an image(other resource) in a Windows Phone 7 project : as build action "Content" or build action "Resource". In this tutorial I will give some examples of how to reference images depending on their build action and will share some performance tips as well.
To begin with lets first say that in this demo I will use the following structure of the images:
Performance Consideration
For a better performance we would suggest that you compile your images with a "Build Action" of "Content" instead of the default "Resource". When adding new images to your project by default the "Build Action" is set to "Resource" (under the Properties window). Make sure to always change this to "Content" in order to reduce the size of your DLL, speeding up both app load and image load.
Content
If you set the build action to "Content" the image is included in the XAP alongside the DLL.
When you use "Build Action" of type "Content" then you access your image in this way:
XAML:
<
Image
Stretch
=
"None"
Source
=
"/images/appbar.cancel.rest.png"
/>
C#:
//Content
Uri uri =
new
Uri(
"/images/appbar.cancel.rest.png"
, UriKind.Relative);
BitmapImage imgSource =
new
BitmapImage(uri);
this
.image.Source = imgSource;
Resource
All resources are embedded in your assembly (DLL).
When you use "Build Action" of type "Resource" then you access your image in this way:
XAML:
<
Image
Source
=
"/WP7SampleProject3;component/images/appbar.feature.email.rest.png"
/>
C#:
//Resource
Uri uriR =
new
Uri(
"/WP7SampleProject3;component/images/appbar.feature.email.rest.png"
, UriKind.Relative);
BitmapImage imgSourceR =
new
BitmapImage(uriR);
this
.imageR.Source = imgSourceR;
Relative or Absolute URI?
Relative URI
Relative URIs specify the location of a resource file relative to the application root or the referencing XAML.
Absolute Uri
Absolute URIs specify the exact location of a resource file, and bypass the fallback mechanism.
RelativeOrAbsolute
If you are not sure whether of these two options to use you can waylays use the RelativeOrAbsolute.
For any reference you can take a look at the MSDN documentation.
You can get the full source code here.
- WP7 working with Images: Content vs Resource build action
- Working with Docker Images
- WP7-Build Action详解
- Working with Images in Google's Android
- Content Type working with Document Word
- WP7开发解惑:BuildAction之Content与Resource
- UFLDL学习笔记7(Working with Large Images)
- Resource.Images
- Build Action 设置为 Embedded Resource
- Working with Windows Service Using VS 2005
- Drupal Working with nodes, content types and fields
- 在wp7中读取XML的配置文件,Content与Resource的区别
- 深度学习笔记7 Working with Large Images 卷积特征提取
- Creating from resource images
- build content
- Build Your Own Images
- Build action
- Loading images with GDI+
- eclipse有乱码问题
- typeid详解
- wp Relative uri Absolute uri的区别
- cmd 修改IP
- struts2原理图
- WP7 working with Images: Content vs Resource build action
- 求直线交点 叉积
- Metric Matrice
- linux命令
- 史上最全的 Winlicense 版本
- WP技术网站
- poj 1065 Wooden Sticks (greedy solved) 求最少启动时间。
- 第一个泛型设计,学生表,第一列是姓名,剩下列是分数
- Steve Jobs (1955 - 2011)