|
|
@@ -45,7 +45,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
* @param uri 图片
|
|
|
* @param scene 识别场景类型
|
|
|
*/
|
|
|
- public void startOcrFromUri(Context context, Uri uri, String scene) {
|
|
|
+ public void startOcrFromUri(Context context, Uri uri, String scene, boolean isLandscape) {
|
|
|
getView().showLoading(context.getResources().getString(R.string.loading));
|
|
|
Observable.create(new ObservableOnSubscribe<String>() {
|
|
|
@Override
|
|
|
@@ -55,12 +55,13 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
// 这个如果是竖屏拍的照片,需要顺时针旋转90度才正常
|
|
|
Bitmap rawBitmap = ImageUtil.getBitmapFromUri(context, uri);
|
|
|
String filePath = ImageOrientation.getPath(context, uri);
|
|
|
- Bitmap rotatedBitmap = null;
|
|
|
+ // 肉眼看见的Bitmap
|
|
|
+ Bitmap viewedBitmap = null;
|
|
|
if (!TextUtils.isEmpty(filePath)) {
|
|
|
- rotatedBitmap = ImageOrientation.modifyOrientation(filePath, rawBitmap);
|
|
|
+ viewedBitmap = ImageOrientation.modifyOrientation(filePath, rawBitmap);
|
|
|
}
|
|
|
|
|
|
- if (rotatedBitmap == null) {
|
|
|
+ if (viewedBitmap == null) {
|
|
|
photoBase64 = Base64Tool.getBase64FromUri(context, uri);
|
|
|
if (TextUtils.isEmpty(photoBase64)) {
|
|
|
emitter.onError(new Exception("Empty image"));
|
|
|
@@ -68,6 +69,12 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
emitter.onNext(photoBase64);
|
|
|
}
|
|
|
} else {
|
|
|
+ Bitmap rotatedBitmap = viewedBitmap;
|
|
|
+ if (isLandscape) {
|
|
|
+ rotatedBitmap = ImageUtil.rotateBitmap(viewedBitmap, -90);
|
|
|
+ viewedBitmap.recycle();
|
|
|
+ }
|
|
|
+
|
|
|
int max = rotatedBitmap.getWidth() > rotatedBitmap.getHeight() ? rotatedBitmap.getWidth() : rotatedBitmap.getHeight();
|
|
|
int multi = 1;
|
|
|
if (max > 1000) {
|
|
|
@@ -185,7 +192,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
int realWidth;
|
|
|
int realHeight;
|
|
|
|
|
|
- boolean isLandscape = mBottom-mTop > mRight-mLeft;
|
|
|
+ //boolean isLandscape = mBottom-mTop > mRight-mLeft;
|
|
|
|
|
|
// 图片宽度与屏幕宽度的比
|
|
|
float widthD = 1.0f * normalWidth / SizeTool.SCREEN_WIDTH;
|
|
|
@@ -233,7 +240,8 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
|
|
|
// 旋转90度,让OCR可以识别
|
|
|
Bitmap rotatedBitmap;
|
|
|
- if (isLandscape) {
|
|
|
+ //if (isLandscape) {
|
|
|
+ if (isScreenLandscape) {
|
|
|
rotatedBitmap = ImageUtil.rotateBitmap(croppedBmp, -90);
|
|
|
} else {
|
|
|
rotatedBitmap = croppedBmp;
|