详细问题描述
[内容]
进行图片裁剪时,摄像头无法调用,如果是在线打包可以,如果嵌入到我原生代码中就不行。请问这是什么问题。
file://storage/emulated/0/Android/data/com.example.nyapp/documents/150305412663.jpg exposed beyond app through ClipData.Item.getUri();
var cropper = null;
mui.plusReady(function() {
var currentId = plus.webview.currentWebview().userId;
document.getElementById("moreMenus").addEventListener("tap", function() {
var editButtons = new Array();
editButtons.push({
title: "拍照",
style: "default"
});
editButtons.push({
title: "相册",
style: "default"
});
plus.nativeUI.actionSheet({
cancel: "取消",
buttons: editButtons
}, function(e) {
var index = e.index;
switch(index) {
case 1:
captureImage(); //拍照
break;
case 2:
selectImage(); //相册选择
break;
}
});
});
//确定裁切
document.getElementById("confirm_id").addEventListener("tap", function(e) {
var dataURL = $("#userImage_id").cropper("getCroppedCanvas", {
width: 300,
height: 300
});
var imgUrl = dataURL.toDataURL("image/png", 1);
// $("#userImage_id").attr("src" , imgUrl);
$("#userImage_id").cropper("replace", imgUrl);
$("#userImage_id").cropper("clear"); //裁切完成取消显示裁切框
$("#userImage_id").cropper("disable");
//确定裁切后销毁裁切组件,标记一下,下次继续裁切时需要初始化一下裁切组件
window.imageDisable = true;
//禁用几个功能按钮
$("button.toolbutton").prop("disabled", true);
//向后台提供数据
saveImage(imgUrl, "_doc/avterImage.jpg");
});
//初始化裁切组件
initImageCropper();
});
//拍照
function captureImage() {
var cmr = plus.camera.getCamera(2);
cmr.captureImage(
function(path) {
//将图片地址转换
plus.io.resolveLocalFileSystemURL(path, function(entry) {
var newPath = entry.toLocalURL() + "?version=" + Math.random();
loadImage(newPath);
});
},
function(error) {
mui.toast(error.message);
}, {
filename: "_documents/"
}
);
}
function initImageCropper() {
//初始化组件
cropper = $("#userImage_id").cropper({
aspectRatio: 3 / 3,
autoCropArea: 1,
dragMode: "move", //设置移动图片、重新绘制选图区域
cropBoxResizable: false,
//movable: true,//是否允许移动裁切框
zoomable: false, //是否允许放大图片
guides: true, //取消显示裁切线中间的虚线网格
minContainerWidth: 300,
minContainerHeight: 300,
minCanvasWidth: 300,
minCanvasHeight: 300,
crop: function(data) {
//初始化
window._scaleX = data.scaleX;
window._scaleY = data.scaleY;
}
});
}
//选择图片
function selectImage() {
plus.gallery.pick(function(path) {
loadImage(path);
}, function(e) {
mui.toast("没有选择图片.");
});
}
//确定选择图片
function loadImage(path) {
var img = document.getElementById("userImage_id");
img.src = path;
if(window.imageDisable == true) {
$("#userImage_id").cropper("enable");
}
$("#userImage_id").cropper("replace", path);
//启用几个功能按钮
$("button.toolbutton").prop("disabled", false);
document.getElementById("userImage_id").onclick = function() {
plus.runtime.openFile(path);
}
}
运行环境
[系统版本]
[浏览器版本]
[IDE版本]
[mui版本]
附件
[代码片段]
[安装包]
联系方式
[QQ] 58227926
[电话]15559557126