標籤:idt jpg open ima one new toast 路徑 turn
在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; }
IOS 照相問題