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

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds