• android 图片拍照图片旋转的处理方式


    第一种:String str=path;

                

    /**
    * 读取图片属性:旋转的角度
    *
    * @param path
    * 图片绝对路径
    * @return degree旋转的角度
    */
    private void readPictureDegree(String filePath) {
    int angle = 0;
    try {
    ExifInterface exifInterface = new ExifInterface(filePath);
    int orientation = exifInterface.getAttributeInt(
    ExifInterface.TAG_ORIENTATION,
    ExifInterface.ORIENTATION_NORMAL);

    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
    angle = 90;
    break;
    case ExifInterface.ORIENTATION_ROTATE_180:
    angle = 180;
    break;
    case ExifInterface.ORIENTATION_ROTATE_270:
    angle = 270;
    break;
    }
    } catch (IOException e) {
    e.printStackTrace();
    }

    if (filePath != null) {
    Bitmap newBitmap = BitmapFactory.decodeFile(filePath);// 根据Path读取资源图片
    Bitmap bitmap = ImageTools
    .zoomBitmap(newBitmap, newBitmap.getWidth() / SCALE,
    newBitmap.getHeight() / SCALE);

    if (angle != 0) {
    // 下面的方法主要作用是把图片转一个角度,也可以放大缩小等
    Matrix m = new Matrix();

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    m.setRotate(angle); // 旋转angle度

    bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, m,
    true);// 从新生成图片

    }
    if (bitmap != null) {
    mListBitmap.add(bitmap);
    creatImage(mListBitmap);
    }
    // 由于Bitmap内存占用较大,这里需要回收内存,否则会报out of memory异常
    // bitmap.recycle();
    }
    }

    第二种:Uri uri=null;

      

    private void setImage(Uri mImageCaptureUri) {
    // 不管是拍照还是选择图片每张图片都有在数据中存储也存储有对应旋转角度orientation值
    // 所以我们在取出图片是把角度值取出以便能正确的显示图片,没有旋转时的效果观看

    ContentResolver cr = this.getContentResolver();
    Cursor cursor = cr.query(mImageCaptureUri, null, null, null, null);// 根据Uri从数据库中找
    if (cursor != null) {
    cursor.moveToFirst();// 把游标移动到首位,因为这里的Uri是包含ID的所以是唯一的不需要循环找指向第一个就是了
    String filePath = cursor.getString(cursor.getColumnIndex("_data"));// 获取图片路
    String orientation = cursor.getString(cursor
    .getColumnIndex("orientation"));// 获取旋转的角度
    cursor.close();
    if (filePath != null) {
    Bitmap newBitmap = BitmapFactory.decodeFile(filePath);// 根据Path读取资源图片
    Bitmap bitmap = ImageTools.zoomBitmap(newBitmap,
    newBitmap.getWidth() / SCALE, newBitmap.getHeight()
    / SCALE);

    int angle = 0;
    if (orientation != null && !"".equals(orientation)) {
    angle = Integer.parseInt(orientation);
    }
    if (angle != 0) {
    // 下面的方法主要作用是把图片转一个角度,也可以放大缩小等
    Matrix m = new Matrix();

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    m.setRotate(angle); // 旋转angle度

    bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height,
    m, true);// 从新生成图片

    }
    if (bitmap != null) {
    mListBitmap.add(bitmap);
    creatImage(mListBitmap);
    }
    // 由于Bitmap内存占用较大,这里需要回收内存,否则会报out of memory异常
    // bitmap.recycle();
    }
    }
    }

  • 相关阅读:
    20135213 20135231 信息安全系统设计基础课程第二次实验报告
    20135213——信息安全系统设计基础第十二周学习总结
    20135213——信息安全系统设计基础第十一周学习总结
    20135220谈愈敏Blog5_系统调用(下)
    20135220谈愈敏Linux Book_5
    20135220谈愈敏Blog4_系统调用(上)
    20135220谈愈敏Linux Book_1&2
    20135220谈愈敏Blog3_构造一个简单的Linux系统MenuOS
    20135220谈愈敏Blog2_操作系统是如何工作的
    20135220谈愈敏Blog1_计算机是如何工作的
  • 原文地址:https://www.cnblogs.com/yujian-bcq/p/3440982.html
Copyright © 2020-2023  润新知