zoukankan      html  css  js  c++  java
  • IOS 照相问题

    在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);
    	}

        为了判断ios 拍照、从相册选取拍照、选取截图照片。如下代码

    // 获得图片和屏幕的宽度,以及比例
    var imgtemp = new Image();
    imgtemp.src = img.src;
    var imgWidth;
    var imgHeight;
    var proportion;
    console.log('max width' + imgtemp.width);
    console.log('max height' + imgtemp.height);
    console.log('min width' + img.width);
    console.log('min height' + img.height);
    var displayWidth = plus.display.resolutionWidth;
    var system = plus.os.name;
    if(system !== 'Android' && parseInt(camera)==1){
    console.log('max width' + imgtemp.width);
    console.log('max height' + imgtemp.height);
    imgWidth = imgtemp.height;
    imgHeight = img.height;
    proportion= getProportion(imgWidth, displayWidth);
    }else{
    if(imgtemp.width == 3264 && imgtemp.height == 2448 && system !== 'Android'){
    console.log('max width' + imgtemp.width);
    console.log('max height' + imgtemp.height);
    imgWidth = imgtemp.height;
    imgHeight = img.height;
    proportion= getProportion(imgWidth, displayWidth);
    }else{
    console.log('width' + imgtemp.width);
    console.log('height' + imgtemp.height);
    imgWidth = imgtemp.width;
    imgHeight = img.height;
    proportion = getProportion(imgWidth, displayWidth);
    }

    }


      

    img.setAttribute("width", plus.display.resolutionWidth);

    // 计算图片和显示屏的比例 function getProportion(imgW, displayW) { return imgW / displayW; }

      

  • 相关阅读:
    Leetcode 421.数组中两数的最大异或值
    Leetcode 419.甲板上的战舰
    Leetcode 417.太平洋大西洋水流问题
    Leetcode 416.分割等和子集
    Leetcode 413.等差数列划分
    Leetcode 410.分割数组的最大值
    由股票价格形成因素看如何选股(发布于06-02 13:09)
    巴菲特的资产配置艺术(发布于06-01 13:28)
    ROE能否包打天下?(发布于05-31 11:27)
    价值迟迟不回归怎么办?(发布于05-30 10:02)
  • 原文地址:https://www.cnblogs.com/RAINHAN/p/7131295.html
Copyright © 2011-2022 走看看