Array

Camera

Must Read

All About Federal Student Loan Consolidation and Its Specific Features

Student loan consolidation is essentially considered as a tool to manage one or more debts. Such a loan also...

How School Loan Consolidation Can Save You Money

Paying off your school loans is not the most pleasant experience, but it can be made easier if you...

Best Practices – Ten questions to answer before choosing commercial software

As the technology continues to progress, hundreds of software on the market are available. As an IT manager or...
Admin
test

All Windows Phone 7 physical devices include a high resolution camera. This is managed by the operating system, but your applications can invoke the camera using the CameraCaptureTask chooser.

To use the camera, you must do the following:

  • Add a reference to the assembly Microsoft.Phone.Tasks to your project.
  • Create a new CameraCaptureTask chooser instance as a global scoped variable (the application will be deactivated when the chooser is launched).
  • Specify a callback in the form of an event handler, or a lambda expression that will receive the picture when the user closes the chooser.
  • Show the chooser.

The camera is designed to be used in landscape mode, and it generates a picture in landscape format. The Exchangeable Image File (EXIF) headers in the image file indicate the correct orientation of the picture, and the photos application in the camera will automatically display the image in the correct orientation. However, in your own applications, you may need to rotate the image to obtain the correct orientation.

A library that you can use to read EXIF information in an image is available from “Understanding and Reading Exif Data” on The Code Project website (http://www.codeproject.com/KB/silverlight/Exif_Data.aspx). Details of how to rotate an image can be found in post, “Handling picture orientation in CameraCaptureTask in Windows Phone 7,” on Tim Heuer’s blog (http://timheuer.com/blog/archive/2010/09/23/working-with-pictures-in-camera-tasks-in-windows-phone-7-orientation-rotation.aspx).

The following code example shows how you can use the Camera CaptureTask chooser to capture a photo.

C#
CameraCaptureTask ctask = new CameraCaptureTask();
ctask.Completed += new EventHandler<PhotoResult>
(ctask_Completed);
ctask.Show();

You then access the picture that the user captured in your event handler. The user may have taken and discarded several photos, and the chooser returns only the one the user decided to keep. The following code example shows how you can access the chosen photo and save it into isolated storage on the device as a JPEG image. To use this code, you must add references to the namespaces System. Windows.Media.Imaging, System.IO.ISolatedStorage, and Microsoft. Phone (for the PictureDecoder class).

C#
void ctask_Completed(object sender, PhotoResult e)
{
WriteableBitmap theImage = PictureDecoder.DecodeJpeg
(e.ChosenPhoto);
String pictureName = “MyPhoto.jpg”;
// Create a virtual store and file stream.
// Check for an existing duplicate name.
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
if (myStore.FileExists(pictureName))
{
myStore.DeleteFile(pictureName);
}
IsolatedStorageFileStream myFileStream = myStore.
CreateFile(pictureName);
// Encode the WriteableBitmap into the JPEG stream and
// place it into isolated storage.
Extensions.SaveJpeg(theImage, myFileStream,
theImage.PixelWidth, theImage.PixelHeight, 0, 85);
myFileStream.Close();
}

You can also use interop with the XNA operating system classes in Windows Phone 7 to save the photo to the Media Library, or to interact with the Media Library.

For more information about using the camera in your applications, see “CameraCaptureTask Class” on MSDN (http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.cameracapturetask(VS.92). aspx). You can also download a code sample that demonstrates capturing camera images from “Code Samples for Windows Phone”
on MSDN (http://msdn.microsoft.com/en-us/library/ff431744(VS.92).aspx).

 

Previous articleAccelerometer
Next articleContacts and Messaging

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest News

Underlight As Accent, For Power and The Main Light for Photography

Underlighting, in which fill or accent light comes from under the topic, is not widely used technique in the traditional Portraits,...

How To Fix Overexposure As A Creative Tool, The Complete Guide

As an creative tool, overexposure is sort of underrated. What I’m close to propose could be a deliberate and well thought out technique for...

7D Mark II is Canon’s best DSLR cameras without full-frame sensor.

The expected long-awaited Canon EOS 7D Mark II are shipping in November for $ 1,799 without a lens. With a higher price tag, you...

Low key photography and How to isolate your subject.

Low key photography doesn’t depend on underexposure to make its point; the key to low key is that the majority of tones, even correctly...

High Key Lighting Techniques for Professional Photographers

I’ve written many times about high key lighting techniques and how to achieve them. The term “high key” is a bit misleading. As I’ve...

More Articles Like This