Sample Windows* Store App for Camera / Picture Taking

Download Article

Download Sample Windows* Store App for Camera / Picture Taking [PDF 305KB]

Introduction

This sample shows how to use the Windows 8 Media Capture API. The application shows how to set up a preview stream and then adjust different properties of the camera. A photo can be taken at any time by clicking / tapping on the blank image box to the right of the preview stream. I will give a brief explanation of each function and then run through the basics of how the app works.

enumerateCameras():

This function populates the <select> box with all available cameras found on the device.

initCaptureSettings()

The initCaptureSettings() function creates an object of type MediaCaptureInitializationSettings and sets some of the properties. This is built into WinRT, and it makes it very easy to specify various properties. Here we set the streaming capture mode to audio and video and also set the photo capture source to video preview.

releaseMediaCapture()

This function releases the mediaCaptureMgr object and calls for garbage collection.

startDevice()

The startDevice() function creates the MediaCapture object and binds an error handler to it. Afterwards, the async initialization function is called to start the device.

startPreview()

This function sets all of the effects’ default original values, sets the amount each effect increases per button click, and also enables all of the effect buttons for use.

clearEffect()

Resets all effect values to 0.

increaseBrightness()

Event handler called when the increase brightness button is pressed. Increases the effect value by the step value.

decreaseBrightness()

Event handler called when the decrease brightness button is pressed. Decreases the effect value by the step value.

increaseContrast()

Event handler called when the increase contrast button is pressed. Increases the effect value by the step value.

decreaseContrast()

Event handler called when the decrease contrast button is pressed. Decreases the effect value by the step value.

increaseHue()

Event handler called when the increase hue button is pressed. Increases the effect value by the step value.

decreaseHue()

Event handler called when the decrease hue button is pressed. Decreases the effect value by the step value.

increaseFocus()

Event handler called when the increase focus button is pressed. Increases the effect value by the step value.

decreaseFocus()

Event handler called when the decrease focus button is pressed. Decreases the effect value by the step value.

increaseExposure()

Event handler called when the increase exposure button is pressed. Increases the effect value by the step value.

decreaseExposure()

Event handler called when the decrease exposure button is pressed. Decreases the effect value by the step value.

increaseZoom()

Event handler called when the increase zoom button is pressed. Increases the effect value by the step value.

decreaseZoom()

Event handler called when the decrease zoom button is pressed. Decreases the effect value by the step value.

increaseWhiteBal()

Event handler called when the increase white balance button is pressed. Increases the effect value by the step value.

decreaseWhiteBal()

Event handler called when the decrease white balance button is pressed. Decreases the effect value by the step value.

capturePhoto()

This is where we actually take the photo. The function first gets the picture library folder location to put the returned file, and then the function creates the actual file itself. After the file is created, the photo is captured and then saved to that photo. The photo is then sent to the pictures library.

showMessage(message)

This method just makes it easy to display the status of the application to the user.

displayTimeDifference()

This function sets the status to show how long it took to take the photo.

onCameraChange()

This function disables all of the buttons, and calls initCaptureSettings() again. The state before the user hits preview is restored.

initialize()

This function disables every button and calls enumerateCameras(). Every event handler is tied to its corresponding button, and then all of the effect values are set to 0. The user is now ready to start using the application.

Basic Lifecycle

The application starts out by searching for all cameras on the device and then displays them all in a drop-down menu. The user can select whichever camera they want to use and then click “Start Device." If the device was successful in starting up, the preview button enables itself. When the user clicks preview, a video stream will start on the left image box, and all of the property adjustment buttons will be enabled. When the user clicks any of the property adjustment buttons, the preview will change in real time. When the user is satisfied that all the property levels are correct, the user can capture a photo by tapping on the right image box. The photo will be saved to that image box, and a copy will also be saved in the Pictures Library. The time it took to capture the photo displays underneath the right image box after a photo is taken.

About the Author
Cristiano is a Software Applications Engineer with Intel's Software and Solutions Group. Over the past year, Cristiano has worked nearly exclusively with Microsoft* Windows 8 and Intel's new tablet platforms, and has a written a variety of Windows Store applications.

Notices

INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

UNLESS OTHERWISE AGREED IN WRITING BY INTEL, THE INTEL PRODUCTS ARE NOT DESIGNED NOR INTENDED FOR ANY APPLICATION IN WHICH THE FAILURE OF THE INTEL PRODUCT COULD CREATE A SITUATION WHERE PERSONAL INJURY OR DEATH MAY OCCUR.

Intel may make changes to specifications and product descriptions at any time, without notice. Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "undefined." Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them. The information here is subject to change without notice. Do not finalize a design with this information.

The products described in this document may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are available on request.

Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order.

Copies of documents which have an order number and are referenced in this document, or other Intel literature, may be obtained by calling 1-800-548-4725, or go to: http://www.intel.com/design/literature.htm

Software and workloads used in performance tests may have been optimized for performance only on Intel microprocessors. Performance tests, such as SYSmark and MobileMark, are measured using specific computer systems, components, software, operations, and functions. Any change to any of those factors may cause the results to vary. You should consult other information and performance tests to assist you infully evaluating your contemplated purchases, including the performance of that product when combined with other products.

Any software source code reprinted in this document is furnished under a software license and may only be used or copied in accordance with the terms of that license.

Intel and the Intel logo are trademarks of Intel Corporation in the US and/or other countries.

Copyright © 2012 Intel Corporation. All rights reserved.

*Other names and brands may be claimed as the property of others.

For more complete information about compiler optimizations, see our Optimization Notice.

Comments

these articles and source

these articles and source codes of apps are great and helpful in developing future apps.these source codes encourages new developers to develop more new source codes with the proper tools and knowledge. hoping to get more apps and their corresponding source codes in the future.