The function returns a base64 encoded string representation of the image taken using the camera (or photo library), in JPEG format. There is an option to specify JPEG quality (0 for max compression up to 100 for min compression).
As you can see from the code below, the base64 data is used in a data url for an <img>. The image shows up fine in UIWebView.
-------
VERSION NOTE:
As of today, in the Edge source, there is support for a "sourceType" option (see code below). For non-Edge versions (pre-0.8.2), grab the patch
here.
The code below is backwards-compatible for iPhone PhoneGap versions below 0.8.2.
-------
Sample javascript (put in a script tag somewhere):
function PictureSourceType() {};
PictureSourceType.PHOTO_LIBRARY = 0;
PictureSourceType.CAMERA = 1;
function getPicture(sourceType)
{
var options = { quality: 10 };
if (sourceType != undefined) {
options["sourceType"] = sourceType;
}
// if no sourceType specified, the default is CAMERA
navigator.camera.getPicture(getPicture_Success, null, options);
};
function getPicture_Success(imageData)
{
alert("getpic success");
document.getElementById("test_img").src = "data:image/jpeg;base64," + imageData;
}
------
In your <body> put:
<img style="width:60px;height:60px" id="test_img" src="" />
<!-- for testing, add the buttons below -->
<button onclick="getPicture()">From Camera</button>
< button onclick="getPicture(PictureSourceType.PHOTO_LIBRARY)">From Photo Library</button>
Comments (3)
pixelpossible said
at 10:41 am on Nov 27, 2009
I am assuming this is only possible with the PhoneGap framework and not part of native navigator object. Is this true? Thanks!
Shazron Abdullah said
at 10:44 am on Nov 27, 2009
Yes of course.
pixelpossible said
at 10:51 am on Nov 27, 2009
Excellent! Thanks Shazron!
You don't have permission to comment on this page.