在iphone上时而出问题时而正常。反复测试后发现问题出在使用iphone摄像头拍摄的照片,这些照片尺寸是3264x2448,但是其实照片的尺寸是2448x3264,宽和高正好是相反的,后来我把照片导到电脑里,的确尺寸应该是2448x3264。原因是iPhone拍摄的图片的起始点是屏幕的左下角,所以宽和高是相反的。。
以下是通过mui 拍照功能、裁剪图片上传判断。
// 拍照操作 function getImage() { plus.camera.getCamera().captureImage(function(path) { plus.io.resolveLocalFileSystemURL(path, function(entry) { var path = entry.toLocalURL(); var filename = entry.name; goShowImg(path, filename,1); }, function(e) { plus.nativeUI.toast("读取拍照文件错误:" + e.message); }); }, function(e) {}, { filename: "_doc/camera/", index: 1 }); } // 相册选取 function galleryImg() { plus.gallery.pick(function(path) { var filename = ‘images.jpg‘; // alert(‘路径:‘ + path); goShowImg(path, filename,0); }, function(e) { console.log("取消选择图片"); }, { filter: "image" }); }
// 跳转到裁剪页面 function goShowImg(path, filename,camera) { // alert(‘我要跳转了‘); console.log(‘camera: ‘ + camera) var image = new Image(); image.src = path; mui.openWindow({ url: ‘clip_img.html‘, id: ‘clip_img.html‘, extras: { path: path, filename: filename, idName: ‘goods_add.html‘, camera: camera }, show: { autoShow: false } }); }
// 获得图片和屏幕的宽度,以及比例 var imgtemp = new Image(); imgtemp.src = img.src; var imgWidth; var imgHeight; var proportion; var displayWidth = plus.display.resolutionWidth; var system = plus.os.name; if(system !== ‘Android‘ && parseInt(camera)==1){ imgWidth = imgtemp.width; imgHeight = imgtemp.height; proportion= getProportion(imgHeight, displayWidth); }else{ imgWidth = imgtemp.width; imgHeight = img.height; proportion = getProportion(imgWidth, displayWidth); }
img.setAttribute("width", plus.display.resolutionWidth); // 计算图片和显示屏的比例 function getProportion(imgW, displayW) { return imgW / displayW; }
时间: 2024-10-12 11:40:02