zoukankan      html  css  js  c++  java
  • apk图像旋转问题

    问题:
    有的手机拍摄的图片旋转90度,有的图片旋转了180度,有的手机是正常的,现在要求的是正的。

    解决措施:
    获得不同手机,图像被旋转的角度,逆旋转回去。


    参考:
    https://www.jb51.net/article/93261.htm
    https://www.jianshu.com/p/a360b32ec9b3


    思路:
    1、EXIF是图像文件的信息
    2、先读图 根据EXIF 判断角度 然后旋转

    参考代码:
    // Rotate according to EXIF
    int rotate = 0;
    try {
    ExifInterface exif = new ExifInterface(resolver.openInputStream(imageUri));
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_270:
    rotate = 270;
    break;
    case ExifInterface.ORIENTATION_ROTATE_180:
    rotate = 180;
    break;
    case ExifInterface.ORIENTATION_ROTATE_90:
    rotate = 90;
    break;
    }
    } catch(IOException e) {
    Log.e("MainActivity", "ExifInterface IOException");
    }
    Log.d("MainActivity", "rotate = " + rotate);

    Bitmap returnBm = null;
    Matrix matrix = new Matrix();
    matrix.postRotate(rotate);
    try {
    returnBm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    } catch(OutOfMemoryError e) {
    e.printStackTrace();
    }
    if(returnBm == null) {
    returnBm = bitmap;
    }
    if(bitmap!=returnBm) {
    bitmap.recycle();
    }
    return returnBm;

  • 相关阅读:
    关于ugc的一点思考
    Fenng早年间对推荐系统的思考
    对于软件开发的一些思考
    并发排序
    Standford CoreNLP使用
    做事情的方式
    JAVA! static的作用
    struts2学习笔记--使用Validator校验数据
    Struts2中的ModelDriven机制及其运用
    ValueStack与ContentMap (ActionContext.getContext().getValueStack().set())
  • 原文地址:https://www.cnblogs.com/wjjcjj/p/14751617.html
Copyright © 2011-2022 走看看