最近在做一个ORC图片解析的功能,要求解析出数字

但是发现他解析只能解析横着的图片,然后我拍照的时候拍的是竖直照片,当然你也可以去旋转照相机的屏幕

但是我这里为了方便选择的是竖直拍出来

然后,旋转下咯(ps:网上找的通用方法)

方法1. 利用Bitmap.createBitmap

   Bitmap
adjustPhotoRotation(Bitmap bm, final int orientationDegree)
{ Matrix m = new Matrix();
m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); try { Bitmap bm1 = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true); return bm1; } catch (OutOfMemoryError ex) {
} return null; } 方法2. 利用Canvas.drawBitmap Bitmap
adjustPhotoRotation(Bitmap bm, final int orientationDegree)
{ Matrix m = new Matrix();
m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);
float targetX, targetY;
if (orientationDegree == 90) {
targetX = bm.getHeight();
targetY = 0;
} else {
targetX = bm.getHeight();
targetY = bm.getWidth();
} final float[] values = new float[9];
m.getValues(values); float x1 = values[Matrix.MTRANS_X];
float y1 = values[Matrix.MTRANS_Y]; m.postTranslate(targetX - x1, targetY - y1); Bitmap bm1 = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888); Paint paint = new Paint();
Canvas canvas = new Canvas(bm1);
canvas.drawBitmap(bm, m, paint); return bm1;
}

其中方法2的耗时是方法一的一半~

建议是方法二

Bitmap旋转方法的更多相关文章

  1. android--屏幕旋转方法总结

    在介绍之前,我们需要先了解默认情况下android屏幕旋转的机制: 默认情况下,当用户手机的重力感应器打开后,旋转屏幕方向,会导致当前activity发生onDestroy-> onCreate ...

  2. iOS 图片旋转方法

    iOS 图片旋转方法 通过 CGImage 或 CIImage 旋转特定角度 UIImage可通过CGImage或CIImage初始化,初始化方法分别为init(cgImage: CGImage, s ...

  3. 平衡二叉树AVL - 插入节点后旋转方法分析

    平衡二叉树 AVL( 发明者为Adel'son-Vel'skii 和 Landis)是一种二叉排序树,其中每一个节点的左子树和右子树的高度差至多等于1. 首先我们知道,当插入一个节点,从此插入点到树根 ...

  4. Unity - 旋转方法

    前言 本文梳理了Unity中常用的旋转方法,涉及两大类:Transform.Quaternion. Transform 类 Rotate() 此方法重载多,易理解,在连续动态旋转中较为常用. /* o ...

  5. Android中经常使用的bitmap处理方法

    收集了非常多bitmap相关的处理方法,差点儿所有应用在项目中,所以特记录下! package com.tmacsky.utils; import java.io.ByteArrayOutputStr ...

  6. Android 从imageview中获得bitmap的方法

    第一种: 使用setDrawingCacheEnabled()和getDrawingCache()这两种方法,第一个是为了设置是否开启缓存,第二个就可以直接获得imageview中的缓存,一般来说需要 ...

  7. Android 从ImageView中获取Bitmap对象方法

    showImageView.setDrawingCacheEnabled(true); Bitmap bitmap=showImageView.getDrawingCache(); showImage ...

  8. unity-----------------------四元数与欧拉旋转方法

    转:http://blog.csdn.net/treepulse/article/details/49281295 Transfrom.eulerAngles public float yRotati ...

  9. Unity 自己旋转 方法

    transform.Rotate(Vector3.up * Time.deltaTime * 100);

随机推荐

  1. 深入Python(4):深拷贝和浅拷贝

    一.前奏:熟悉Python内存管理 在Python中,变量在第一次赋值时自动声明,在创建---也就是赋值的时候,解释器会根据语法和右侧的操作数来决定新对象的类型. 引用计数器:一个内部跟踪变量 引用计 ...

  2. 帝国CMS内容模板IF判断

    [e:loop={'selfinfo',50,0,0,"jingshu=$navinfor[jingshu]","id"}]<?php$class1=&q ...

  3. navicat------------利用navicat查看两个数据库之间的差异

  4. struts2实现文件上传、多文件上传和文件下载

    总结的两个问题,就是struts2上传下载的时候对属性名配置要求非常严格: 第一:上传的时候 private File file; private String fileContentType; pr ...

  5. HDU 1258 Sum It Up

    Sum It Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  6. UITableView中Cell和section的插入与删除

    插入段: - (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animati ...

  7. Proteus 8 画原理图仿真 1602 LCD显示字符

    以下是源程序: #include <reg52.h> #include<intrins.h> /** * P2 上接的是 D1 ~ D7 */ sbit RS = P3 ^ ; ...

  8. asp.net 之 购物车

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  9. 2016年12月24日 星期六 --出埃及记 Exodus 21:19

    2016年12月24日 星期六 --出埃及记 Exodus 21:19 the one who struck the blow will not be held responsible if the ...

  10. C#获取文件时间

    在NTFS下,文件的创建及修改时间可以精确到毫秒,以下是测试过程. DirectoryInfo diSource = new DirectoryInfo(@"C:\Users\不告诉你\De ...