[英]How to show image taken from camera in Cordova? (Xcode/iOS)
I am able to access the camera and even save the image remotely, but I would like to show the image on the screen before I upload. 我可以访问相机,甚至可以远程保存图像,但是我想在上传之前在屏幕上显示图像。
The function that opens the devices camera is: 打开设备摄像头的功能是:
function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 10, width: 412, height: 412, correctOrientation: 1, saveToPhotoAlbum: 1});
}
The function that is triggered after the photo is initially taken is: 最初拍摄照片后触发的功能是:
function uploadImage() {
imageURI = lastImage;
// Get image handle
var smallImage = document.getElementById('smallImage')
smallImage.src = "data:image/jpeg;base64," + imageURI;
var fail, ft, options, params, win;
// callback for when the photo has been successfully uploaded:
var success = function(response) {
//alert(tags);
alert("Photo Saved");
};
// callback if the photo fails to upload successfully.
var fail = function(error) {
alert("An error has occurred: Code = " + error.code);
alert(FileTransferError.CONNECTION_ERR);
};
//FILE UPLOAD SCRIPTS
options = new FileUploadOptions();
options.fileKey = "my_image";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "text/plain";
params = {
val1: tags,
val2: location
};
options.params = params;
ft = new FileTransfer();
ft.upload(imageURI, 'http://mysite.com/recieve.php', success, fail, options);
}
And the HTML where the image is to be displayed: 以及要显示图像的HTML:
<img style="display :none;width:60px;height:60px;" id="smallImage" src="" />
I am assuming there is something wrong with the line 我假设这条线有问题
smallImage.src = "data:image/jpeg;base64," + imageURI;
but I am not sure what or how to fix it. 但我不确定该如何解决。
Would anyone know how to ammend this? 有人会知道如何修改吗?
I got it. 我知道了。
I changed the line 我换了线
smallImage.src = "data:image/jpeg;base64," + imageURI;
too 太
smallImage.src = imageURI;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.