Download Sample Windows* Store App for Camera / Picture Taking [PDF 305KB]
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.
This function populates the <select> box with all available cameras found on the device.
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.
This function releases the mediaCaptureMgr object and calls for garbage collection.
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.
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.
Resets all effect values to 0.
Event handler called when the increase brightness button is pressed. Increases the effect value by the step value.
Event handler called when the decrease brightness button is pressed. Decreases the effect value by the step value.
Event handler called when the increase contrast button is pressed. Increases the effect value by the step value.
Event handler called when the decrease contrast button is pressed. Decreases the effect value by the step value.
Event handler called when the increase hue button is pressed. Increases the effect value by the step value.
Event handler called when the decrease hue button is pressed. Decreases the effect value by the step value.
Event handler called when the increase focus button is pressed. Increases the effect value by the step value.
Event handler called when the decrease focus button is pressed. Decreases the effect value by the step value.
Event handler called when the increase exposure button is pressed. Increases the effect value by the step value.
Event handler called when the decrease exposure button is pressed. Decreases the effect value by the step value.
Event handler called when the increase zoom button is pressed. Increases the effect value by the step value.
Event handler called when the decrease zoom button is pressed. Decreases the effect value by the step value.
Event handler called when the increase white balance button is pressed. Increases the effect value by the step value.
Event handler called when the decrease white balance button is pressed. Decreases the effect value by the step value.
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.
This method just makes it easy to display the status of the application to the user.
This function sets the status to show how long it took to take the photo.
This function disables all of the buttons, and calls initCaptureSettings() again. The state before the user hits preview is restored.
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.
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
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.