我正在使用phonegap来构建我的应用程序,在我正在构建的应用程序中,我有一个相机,当我打开应用程序时,我会看到相机控件。一旦我捕获图片,捕获的图片应该被设置为我的应用程序背景图像。我怎么能这样做?
这是我尝试过的:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.camera.getPicture(onSuccess, onFail, {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
encodingType: Camera.EncodingType.JPEG,
saveToPhotoAlbum: true,
showOverlay: false
});
function onSuccess(imageURI) {
var image = document.getElementById('myImage');
image.src = imageURI;
alert(image.src);
document.body.style.backgroundImage = "url(image.src)";
}
function onFail(message) {
/*alert("you are closing the camera")*/
}
}
答案 0 :(得分:0)
您的onSuccess
功能应如下所示
function onSuccess(imageData) {
var image = "data:image/jpeg;base64," + imageData;
document.body.style.backgroundImage = "url(" + image + ")";
}