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: September 19, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT In response to the rising number of data breaches and the regulatory and legal impact that can occur as a result of these incidents, leading analysts at Forrester Research have developed five important design principles that will help security professionals reduce their attack surface and mitigate vulnerabilities. Check out this upcoming eSeminar and join Chris Sherman of Forrester Research to learn how to deal with the influx of new device …

  • The first phase of API management was about realizing the business value of APIs. This next wave of API management enables the hyper-connected enterprise to drive and scale their businesses as API models become more complex and sophisticated. Today, real world product launches begin with an API program and strategy in mind. This API-first approach to development will only continue to increase, driven by an increasingly interconnected web of devices, organizations, and people. To support this rapid growth, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds