Practical development skills for Windows Phone (10): image processing skills for Windows Phone

Source: Internet
Author: User

Developing Windows Phone applicationsProgramWhen dealing with images, the following summarizes some of the techniques used to process images in Windows Phone.

1. image format.
2. Image Compilation Method
3. Image Loading Method
4. Image Cache
5. GIF images
6. image size limit
7. Image Selector

1. Image Format

We know that Windows Phone only supports JPG and PNG images. With the help of the imagetools class library, we can use GIF images in Windows Phone. In Windows Phone, we recommend that you use JPG images first, because JPG images are decoded faster than PNG images and GIF images in Windows Phone. Unless PNG images are required for transparent backgrounds, JPG images are recommended. Unless you want to use GIF dynamic images, we recommend that you use less imageils.

2. Image Compilation Method

In Windows Phone 7, the difference between the image "resource" and "content" is that the image generated in the resource mode is compiled into the application assembly (DLL, images generated in the content mode are deployed in the xap package. When you copy your image to a project, the default image generation action is resource, but I usually choose content to get faster. How should we select the image generation method (build action? Each generation method has its own application: Setting the generation method to content means that the application can load image resources more quickly. Setting the generation method to resource is very useful for you to redeploy the program, this is suitable for class library projects.

The other cell is the direction of the slash (/& \) when it is referenced:

Content:<Image Source= "/Imagesascontent/smiley1.png"/>

 

Resource:<Image Source= ".. \ Imagesasresource \ smiley3.png"/> 

3. Image Loading Method

We can load images asynchronously or synchronously.
Set its urisource to asynchronous loading: bitmapimage. urisource = urisource;
Set the file stream to synchronous loading: bitmapimage. setsource (Stream );
Note that asynchronous image loading does not fully enable another thread for operations, because the decoding of the image being downloaded still occurs in the main UI thread. The following is a summary of asynchronous and synchronous loading:
If you load a non-existent image file synchronously, you will get an exception;
If you load a nonexistent image file asynchronously, The imagefailed event is triggered (if you have registered this event );
If you load an existing image file synchronously, The imageopened event is triggered when the file is loaded;
If you load an existing image file asynchronously, The imageopened event will not be triggered when the file is loaded.

4. Image Cache

Image cache is a very useful function. if used properly, it will improve the performance of your application. bitmap cache will visualize elements (visual elements) save as bitmap when they are rendered for the first time. If you use this element later, you will not render it again, but use the cached bitmap.

5. GIF images

For more information about how to display GIF images on Windows Phone, I wrote a blog. If you want to view the practical development skills on Windows Phone (8): Display GIF images on Windows Phone

6. image size limit

Due to the limited screen size, the image resolution is also limited in Windows Phone. In Windows Phone, Ms recommends that the image resolution not exceed 2000*2000.

Due to the limited screen resolution of Windows Phone, another way to optimize performance is to limit the image size to 2000X2000 pixels, which is the size limit of images in Windows Phone environment. larger images will be sampled at a lower resolution. also, if you use images that are larger than 2000X2000 pixels, they will be significantly slower to appear.

7. Image Selector

in our applications, users may need to provide their own image selection functions. In this case, photochoosertask is useful. He has a completed event and returns the file stream of the selected photo, we can set the stream to the image control on the page. The common usage is as follows:
here is a tip: photochoosertask you can return an image of a specified pixel. That is, if you only want to obtain the part of the image as the return result, you only need to set the pixelheight and pixelwidth .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.