Working with High Resolution Images in Your Windows Phone Applications

Introduction

With the emergence of better cameras in mobile phones, users are taking photos of increasingly higher resolutions. Image quality is getting better, and the image sizes are correspondingly increasing. High image quality shots take a lot of disk space, so it is important to be judicious when it comes to determining what resolution you want to store the images in your Camera roll.

The best camera in the mobile world is the one in Lumia 1020, which has a sensor size of 1/1.5”. The sensor supports 7712x5360 pixel resolution (41.3MP), and in 16:9 mode, a pixel size of 7712x4352 is supported (33.6 MP) and in 4:3 model, a pixel size of 7136 x 5360 (38.2MP) is supported.

A thing to note, by default a camera application might not store images at the highest possible resolution on the device and this is by design to avoid taking up all the storage space.

Instead, applications are recommended to take a photo at the higher resolution and it is scaled down to an acceptable image resolution (in an overexposed mode) to persist to the Camera Roll on the storage device (may be at a 5 MP resolution).

The typical steps of handling a high resolution image are:

1. Take a high resolution image and store it in your application local storage.

2. Scale down the image to a 5MP or lower resolution (in an overexposed mode).

3. Store the smaller image on the camera roll.

4. On a periodic basis, clear the application local storage.

How to Take High Resolution Images

To take a high resolution image, set the resolution of the PhotoCaptureDevice to the desired mode.

First, get the resolution of the camera.

var resolution = PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);

If this is not the desired resolution, set it to the correct resolution desired for the image.

resolution = new Windows.Foundation.Size(resolutionWidth, resolutionHeight);
PhotoCaptureDevice device = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, resolution);

Once the photo is taken, store the high resolution image to the local storage. To do this, get the user store for the application using the GetUserStoreForApplication() API on the IsolatedStorageFile class,  and create a destination to store the image. Get the image as a stream by calling image.AsStream() and flush the contents of the file.

Next, to save the image to the camera roll, scale it down to an acceptable size with oversampling.

You can use the Nokia Imaging SDK to do this. You will convert the image to a BitMap and then scale it down.

Use the AutoResizeConfiguration API on the Nokia.Graphics.Imaging.AutoResizeConfiguration class to specify the desired resolution of the scaled image.

To save the image to the camera roll:

var library = new Microsoft.Xna.Framework.Media.MediaLibrary() 
{ 
     using (var picture = library.SavePictureToCameraRoll(filenameBase, libraryImage)) 
     { 
	      savedPath = picture.GetPath(); 
     }
 } 

Now, your scaled down image is in the camera roll.

The final step is the clear the isolated storage of your application.

You can delete the temporary files you have created upon application exit.

You can iterate over the entire isolated store and delete the files you don’t need by calling IsolatedStorageFile.DeleteFile() API.

Now, you have enabled your application to handle high resolution images.

Summary

In this article, we learned about handling high resolution images in your Windows Phone application. I hope you have found this information useful.

About the author

Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at vipul.patel@hotmail.com



Related Articles

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Savvy enterprises are discovering that the cloud holds the power to transform IT processes and support business objectives. IT departments can use the cloud to redefine the continuum of development and operations—a process that is becoming known as DevOps. Download the Executive Brief DevOps: Why IT Operations Managers Should Care About the Cloud—prepared by Frost & Sullivan and sponsored by IBM—to learn how IBM SmartCloud Application services provide a robust platform that streamlines …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds