cordova 相机未在 div 中显示图像
cordova camera not showing image in div
除了 div 没有显示照片外,一切正常,我不确定我哪里出错了。我正在使用最新版本的 phonegap cli-5.2.0,我一遍又一遍地查看文档,试图找到我可能出错的地方
html
<div id="myImage"></div>
CSS
#myImage
{
width:80%;
padding:2%;
left:7.5%;
top:15%;
background-color:#111;
height:50%;
border: 3px solid #111;
}
JS
$(document).ready(function() {
$("#camera").click(function() {
navigator.camera.getPicture(onSuccess, onFail, {
quality : 75,
destinationType: Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: true });
function onSuccess(imageURI) {
var image = document.getElementById('myImage');
image.src = imageURI;
}
function onFail(message) {
alert('Failed because: ' + message);
}
});
});
你不能把图片放在div上,div没有src,你必须把它放在img标签上
<img id="myImage" src=""/>
好的,然后你想同时使用下面的代码,然后首先尝试 android。
<img id="myImage" >
<script type="text/javascript">
var profileImage = '';
function profileCapturePhotoEdit() {
navigator.camera.getPicture(profileonPhotoDataSuccess, onFail, {
quality: 20, allowEdit: true,
correctOrientation: true,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA }
);
}
function profileonPhotoDataSuccess(imageData) {
localStorage.setItem("imageDataProfile","data:image/jpeg;base64," + imageData);
var imageDataProfile = localStorage.getItem("imageDataProfile");
document.getElementById('myImage').src = imageDataProfile;
}
function onFail(message) {
// alert('Failed because: ' + message);
}
</script>
并为 android 添加 cordova.js 和相机相关权限。
我认为 "saveToPhotoAlbum Option" 必须是错误的
除了 div 没有显示照片外,一切正常,我不确定我哪里出错了。我正在使用最新版本的 phonegap cli-5.2.0,我一遍又一遍地查看文档,试图找到我可能出错的地方
html
<div id="myImage"></div>
CSS
#myImage
{
width:80%;
padding:2%;
left:7.5%;
top:15%;
background-color:#111;
height:50%;
border: 3px solid #111;
}
JS
$(document).ready(function() {
$("#camera").click(function() {
navigator.camera.getPicture(onSuccess, onFail, {
quality : 75,
destinationType: Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: true });
function onSuccess(imageURI) {
var image = document.getElementById('myImage');
image.src = imageURI;
}
function onFail(message) {
alert('Failed because: ' + message);
}
});
});
你不能把图片放在div上,div没有src,你必须把它放在img标签上
<img id="myImage" src=""/>
好的,然后你想同时使用下面的代码,然后首先尝试 android。
<img id="myImage" >
<script type="text/javascript">
var profileImage = '';
function profileCapturePhotoEdit() {
navigator.camera.getPicture(profileonPhotoDataSuccess, onFail, {
quality: 20, allowEdit: true,
correctOrientation: true,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA }
);
}
function profileonPhotoDataSuccess(imageData) {
localStorage.setItem("imageDataProfile","data:image/jpeg;base64," + imageData);
var imageDataProfile = localStorage.getItem("imageDataProfile");
document.getElementById('myImage').src = imageDataProfile;
}
function onFail(message) {
// alert('Failed because: ' + message);
}
</script>
并为 android 添加 cordova.js 和相机相关权限。
我认为 "saveToPhotoAlbum Option" 必须是错误的