zoukankan      html  css  js  c++  java
  • 三星手机调用系统相机问题整理及解决方案

    (转载请出名出处:http://www.cnblogs.com/alexcai/p/5395158.html

    最近发现三星Note 3手机在使用MediaStore.ACTION_IMAGE_CAPTURE调起系统相机后拍照会有一些问题,现在把问题和解决方案记录下来,以备以后参考。

    1、调起相机后activity destory

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    startActivityForResult(intent, 1);

    发现onActivityResult时,原来存在activity里的变量都复原了,研究了半天才发现原来是被destory了,其他手机都是好的。

    上网找了半天,找到了解决方案:(参考:https://www.zhihu.com/question/21541629

    原因其实是在调起系统相机后,屏幕尺寸发生变化,导致activity被销毁,解决方案:

    在配置文件里配置activity属性:android:configChanges="orientation|keyboardHidden|screenSize"(主要是screenSize)

     

    2、相机返回照片旋转(从相册选取的照片也有此问题)

    这个问题好解决,主要是因为相机拍摄照片的默认方向问题,可以通过读取照片exif信息,并且进行相应旋转即可:(参考:http://www.lxway.com/4451865596.htm

      

      /**
    * 读取照片exif信息中的旋转角度 * @param path 照片路径 * @return角度 */ public static 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; } /** * 将图片按照某个角度进行旋转 * @param bm 需要旋转的图片 * @param degree 旋转角度 * @return 旋转后的图片 */ public static Bitmap rotateBitmapByDegree(Bitmap bm, int degree) { Bitmap returnBm = null;// 根据旋转角度,生成旋转矩阵 Matrix matrix = new Matrix(); matrix.postRotate(degree); try { // 将原始图片按照旋转矩阵进行旋转,并得到新的图片 returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); } catch (OutOfMemoryError e) { e.printStackTrace(); } if (returnBm == null) { returnBm = bm; } if (bm != returnBm) { try { bm.recycle(); } catch(Exception e) { e.printStackTrace(); } } return returnBm; }

    使用时:

    //1.File -> Bitmap
    final BitmapFactory.Options options = new BitmapFactory.Options();
    Bitmap bitmap = BitmapFactory.decodeFile(path, options);
    //2.Bitmap Rotate
    int degree = readPictureDegree(path);
    Bitmap bitmap_r = rotateBitmapByDegree(bitmap, degree);

    (转载请出名出处:http://www.cnblogs.com/alexcai/p/5395158.html

     

  • 相关阅读:
    @RequestParam 加与不加的区别
    spring boot 实战
    mongo入门
    npm install 错误记录
    AsyncConfigurer 线程池
    guava Preconditions
    mysql分组、合并语句
    maven的学习以及集成开发软件
    Spring MVC+Junit测试出错---@WebAppConfiguration
    mybatis的代码生成器
  • 原文地址:https://www.cnblogs.com/alexcai/p/5395158.html
Copyright © 2011-2022 走看看