• 三星手机拍照后显示图片角度旋转问题的解决方法


              项目开发中,须要用一个ImageView显示拍照的图片。

    在使用三星手机进行測试的时候发现图片角度发生了旋转,经资料查询,这是由于三星手机拍照的图片旋转角度是90度,而其它手机是0度。这样思路就出来了:先查询被旋转了多少度,然后再旋转回来。ok。以下上代码。


    首先是读取图片被旋转的角度。

    	/**
    	 * 读取照片exif信息中的旋转角度
    	 * @param path  照片路径
    	 * @return 角度
    	 */
    	public int readPictureDegree(String path) {
    		int degree = 0;
    		try {
    			ExifInterface exifInterface = new ExifInterface(path);
    			int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
    					ExifInterface.ORIENTATION_NORMAL);
    			switch (orientation) {
    			case ExifInterface.ORIENTATION_ROTATE_90:
    				degree = 90;
    				break;
    			case ExifInterface.ORIENTATION_ROTATE_180:
    				degree = 180;
    				break;
    			case ExifInterface.ORIENTATION_ROTATE_270:
    				degree = 270;
    				break;
    			}
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		return degree;
    	}

    再接着是将图片旋转回0度。

    	public Bitmap toturn(Bitmap img, String path) {
    		Matrix matrix = new Matrix();
    		matrix.postRotate(readPictureDegree(path)); 
    		int width = img.getWidth();
    		int height = img.getHeight();
    		img = Bitmap.createBitmap(img, 0, 0, width, height, matrix, true);
    		return img;
    	}





  • 相关阅读:
    vim tail
    范式
    $@疑点
    ^ $ 和 a z 字符匹配
    [导入]DataList编辑、更新、取消、删除、分页(分页控件AspNetPager.dll)
    [导入]用.net操作word
    导出文件
    [导入]总结:ADO.NET在开发中的部分使用方法和技巧
    读取DataTable中的数据,一行一行进行比较
    [导入]ASP.NET 数据访问类
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/7357852.html
Copyright © 2020-2023  润新知