Skip to content

Instantly share code, notes, and snippets.

@Rockncoder
Created July 11, 2012 12:01
Show Gist options
  • Select an option

  • Save Rockncoder/3089933 to your computer and use it in GitHub Desktop.

Select an option

Save Rockncoder/3089933 to your computer and use it in GitHub Desktop.
PhoneGap camera device getPicture()
RocknCoder.Pages.page1 = (function () {
var dims,
// cache the selectors to some DOM elements
$thePicture = $("#thePicture"),
$snapPicture = $("#snapPicture"),
$picFrame = $("#picFrame"),
// once the image is loaded, get its dimensions
picLoaded = function () {
var width, height;
width = $thePicture.width();
height = $thePicture.height();
// cause the image to scale by setting one of it dimension
if (width > height) {
$thePicture.width(RocknCoder.Container.width);
} else {
$thePicture.height(RocknCoder.Container.height);
}
},
// a picture has been successfully returned
picSuccess = function (imageData) {
$thePicture.attr('src', "data:image/jpeg;base64," + imageData).load(picLoaded);
},
// there was an error, message contains its cause
picFail = function (message) {
alert("Failed because: " + message);
},
// pageshow event handler
pageshow = function () {
RocknCoder.Dimensions.init();
dims = RocknCoder.Dimensions.getContent();
$("#picFrame").css({
width: dims.width,
height: dims.height
});
RocknCoder.Container = {
width: dims.width,
height: dims.height
};
$snapPicture.unbind('tap').tap(function (event) {
event.preventDefault();
event.stopPropagation();
navigator.camera.getPicture(
picSuccess,
picFail,
{quality: 35, destinationType: Camera.DestinationType.DATA_URL}
);
return false;
});
},
pagehide = function () {
$snapPicture.unbind('tap');
};
return {
pageshow: pageshow,
pagehide: pagehide
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment