Windows Phone and PhoneGap – Article #12 – Take picture via Camera in Windows Phone
The PhoneGap provides the Camera.getPicture method that lets the user to take photo using the camera in Windows Phone .
Infact , its the camera object that provides access to the Windows Phone Camera in PhoneGap …
To open the Windows Phone’s camera to take the picture , just call the method navigator.camera.getPicture .
The navigator.camera.getPicture accepts 3 parameters
- The first parameter is the function to be called when the picture is taken successfully . You can use this function to display the image in the ImageControl for example .
- The second parameter is the function that should be called on error when taking the picture .
- The third one is the optional parameter where you could specify the source . By default , it is Camera.PictureSourceType.Camera and hence we ignore it for this example .
When a picture is taken taken successfully , a return value (string) is sent to the success function .
By default , the string is the Base64 encoded photo image , but you will also be able to get the image location on the local storage .
function Button1_onclick()
{
navigator.camera.getPicture(onSuccess, onFail, {sourceType : Camera.PictureSourceType.CAMERA});
}
function onSuccess(data)
{ // image is a image control here
var imageControl = document.getElementById('image');
imageControl.src = "data:image/jpeg;base64," + data;
}
function onFail(message)
{ alert('Error taking picture'); }


Windows Dev News for January 31, 2012 – #0034…
body { font-size: 11pt; font-family: ‘Tahoma’; margin:0; padding:0; height:100%;} Windows Dev News for…