|
@@ -198,7 +198,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
//boolean isLandscape = mBottom-mTop > mRight-mLeft;
|
|
//boolean isLandscape = mBottom-mTop > mRight-mLeft;
|
|
|
|
|
|
|
|
// 图片宽度与屏幕宽度的比
|
|
// 图片宽度与屏幕宽度的比
|
|
|
- float widthD = 1.0f * normalWidth / SizeTool.SCREEN_WIDTH;
|
|
|
|
|
|
|
+ float widthD = 1.0f * normalWidth / mWidth;
|
|
|
// 图片高度与屏幕高度的比
|
|
// 图片高度与屏幕高度的比
|
|
|
float heightD = 1.0f * normalHeight / mHeight;
|
|
float heightD = 1.0f * normalHeight / mHeight;
|
|
|
boolean isPortraitPhoto = BigDecimal.valueOf(heightD).compareTo(BigDecimal.valueOf(widthD)) > 0;
|
|
boolean isPortraitPhoto = BigDecimal.valueOf(heightD).compareTo(BigDecimal.valueOf(widthD)) > 0;
|
|
@@ -206,14 +206,14 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
// 高的倍距大,以宽为基准
|
|
// 高的倍距大,以宽为基准
|
|
|
if (widthD > 0) {
|
|
if (widthD > 0) {
|
|
|
// 图片宽要缩小到屏幕宽
|
|
// 图片宽要缩小到屏幕宽
|
|
|
- float pivot = 1.0f * normalWidth / SizeTool.SCREEN_WIDTH;
|
|
|
|
|
|
|
+ float pivot = 1.0f * normalWidth / mWidth;
|
|
|
realLeft = (int) (mLeft * pivot);
|
|
realLeft = (int) (mLeft * pivot);
|
|
|
realTop = (int) (mTop * pivot);
|
|
realTop = (int) (mTop * pivot);
|
|
|
realWidth = (int) ((mRight - mLeft) * pivot);
|
|
realWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
realHeight = (int) ((mBottom - mTop) * pivot);
|
|
realHeight = (int) ((mBottom - mTop) * pivot);
|
|
|
} else {
|
|
} else {
|
|
|
// 屏幕宽要缩小到图片宽
|
|
// 屏幕宽要缩小到图片宽
|
|
|
- float pivot = 1.0f * normalWidth / SizeTool.SCREEN_WIDTH;
|
|
|
|
|
|
|
+ float pivot = 1.0f * normalWidth / mWidth;
|
|
|
realLeft = (int) (mLeft * pivot);
|
|
realLeft = (int) (mLeft * pivot);
|
|
|
realTop = (int) (mTop * pivot);
|
|
realTop = (int) (mTop * pivot);
|
|
|
realWidth = (int) ((mRight - mLeft) * pivot);
|
|
realWidth = (int) ((mRight - mLeft) * pivot);
|
|
@@ -337,60 +337,60 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
|
|
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
|
|
|
// 所以要先恢复原来的图片再裁剪
|
|
// 所以要先恢复原来的图片再裁剪
|
|
|
//Bitmap normalBitmap = ImageUtil.rotateBitmap90(originalBmp);
|
|
//Bitmap normalBitmap = ImageUtil.rotateBitmap90(originalBmp);
|
|
|
- int normalWidth = normalBitmap.getWidth();
|
|
|
|
|
- int normalHeight = normalBitmap.getHeight();
|
|
|
|
|
|
|
+ int rawBitmapWidth = normalBitmap.getWidth();
|
|
|
|
|
+ int rawBitmapHeight = normalBitmap.getHeight();
|
|
|
|
|
|
|
|
// 图片不旋转,以屏幕为参考系进行缩小或者放大,直到图片一条边等于屏幕的一条边,图片的另一条边大于等于屏幕的另一条边
|
|
// 图片不旋转,以屏幕为参考系进行缩小或者放大,直到图片一条边等于屏幕的一条边,图片的另一条边大于等于屏幕的另一条边
|
|
|
int realLeft;
|
|
int realLeft;
|
|
|
int realTop;
|
|
int realTop;
|
|
|
- int realWidth;
|
|
|
|
|
- int realHeight;
|
|
|
|
|
|
|
+ int croppedBitmapWidth;
|
|
|
|
|
+ int croppedBitmapHeight;
|
|
|
|
|
|
|
|
//boolean isLandscape = mBottom-mTop > mRight-mLeft;
|
|
//boolean isLandscape = mBottom-mTop > mRight-mLeft;
|
|
|
|
|
|
|
|
// 图片宽度与屏幕宽度的比
|
|
// 图片宽度与屏幕宽度的比
|
|
|
- float widthD = 1.0f * normalWidth / SizeTool.SCREEN_WIDTH;
|
|
|
|
|
|
|
+ float widthD = 1.0f * rawBitmapWidth / mWidth;
|
|
|
// 图片高度与屏幕高度的比
|
|
// 图片高度与屏幕高度的比
|
|
|
- float heightD = 1.0f * normalHeight / mHeight;
|
|
|
|
|
|
|
+ float heightD = 1.0f * rawBitmapHeight / mHeight;
|
|
|
boolean isPortraitPhoto = BigDecimal.valueOf(heightD).compareTo(BigDecimal.valueOf(widthD)) > 0;
|
|
boolean isPortraitPhoto = BigDecimal.valueOf(heightD).compareTo(BigDecimal.valueOf(widthD)) > 0;
|
|
|
if (isPortraitPhoto) {
|
|
if (isPortraitPhoto) {
|
|
|
// 高的倍距大,以宽为基准
|
|
// 高的倍距大,以宽为基准
|
|
|
- if (widthD > 0) {
|
|
|
|
|
|
|
+ if (widthD > 1) {
|
|
|
// 图片宽要缩小到屏幕宽
|
|
// 图片宽要缩小到屏幕宽
|
|
|
- float pivot = 1.0f * normalWidth / SizeTool.SCREEN_WIDTH;
|
|
|
|
|
|
|
+ float pivot = 1.0f * rawBitmapWidth / mWidth;
|
|
|
realLeft = (int) (mLeft * pivot);
|
|
realLeft = (int) (mLeft * pivot);
|
|
|
realTop = (int) (mTop * pivot);
|
|
realTop = (int) (mTop * pivot);
|
|
|
- realWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
|
|
- realHeight = (int) ((mBottom - mTop) * pivot);
|
|
|
|
|
|
|
+ croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
|
|
+ croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
|
|
|
} else {
|
|
} else {
|
|
|
- // 屏幕宽要缩小到图片宽
|
|
|
|
|
- float pivot = 1.0f * normalWidth / SizeTool.SCREEN_WIDTH;
|
|
|
|
|
- realLeft = (int) (mLeft * pivot);
|
|
|
|
|
- realTop = (int) (mTop * pivot);
|
|
|
|
|
- realWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
|
|
- realHeight = (int) ((mBottom - mTop) * pivot);
|
|
|
|
|
|
|
+ // 屏幕高要缩小到图片高
|
|
|
|
|
+ float pivot = 1.0f * mHeight / rawBitmapHeight;
|
|
|
|
|
+ realLeft = (int) (mLeft / pivot);
|
|
|
|
|
+ realTop = (int) (mTop / pivot);
|
|
|
|
|
+ croppedBitmapWidth = (int) (1.0f * (mRight - mLeft) / pivot);
|
|
|
|
|
+ croppedBitmapHeight = (int) (1.0f * (mBottom - mTop) / pivot);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// 宽的倍距大,以高为基准
|
|
// 宽的倍距大,以高为基准
|
|
|
- if (heightD > 0) {
|
|
|
|
|
|
|
+ if (heightD > 1) {
|
|
|
// 图片高要缩小到屏幕高
|
|
// 图片高要缩小到屏幕高
|
|
|
- float pivot = 1.0f * normalHeight / mHeight;
|
|
|
|
|
|
|
+ float pivot = 1.0f * rawBitmapHeight / mHeight;
|
|
|
realLeft = (int) (mLeft * pivot);
|
|
realLeft = (int) (mLeft * pivot);
|
|
|
realTop = (int) (mTop * pivot);
|
|
realTop = (int) (mTop * pivot);
|
|
|
- realWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
|
|
- realHeight = (int) ((mBottom - mTop) * pivot);
|
|
|
|
|
|
|
+ croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
|
|
+ croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
|
|
|
} else {
|
|
} else {
|
|
|
- // 屏幕高要缩小到图片高,其实一样
|
|
|
|
|
- float pivot = 1.0f * normalHeight / mHeight;
|
|
|
|
|
- realLeft = (int) (mLeft * pivot);
|
|
|
|
|
- realTop = (int) (mTop * pivot);
|
|
|
|
|
- realWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
|
|
- realHeight = (int) ((mBottom - mTop) * pivot);
|
|
|
|
|
|
|
+ // 屏幕宽要缩小到图片宽
|
|
|
|
|
+ float pivot = 1.0f * mWidth / rawBitmapWidth;
|
|
|
|
|
+ realLeft = (int) (mLeft/pivot);
|
|
|
|
|
+ realTop = (int) (mTop/pivot);
|
|
|
|
|
+ croppedBitmapWidth = (int) (1.0f * (mRight - mLeft)/pivot);
|
|
|
|
|
+ croppedBitmapHeight = (int) (1.0f * (mBottom - mTop)/pivot);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- Bitmap croppedBmp = Bitmap.createBitmap(normalBitmap, realLeft, realTop, realWidth, realHeight);
|
|
|
|
|
|
|
+ Bitmap croppedBmp = Bitmap.createBitmap(normalBitmap, realLeft, realTop, croppedBitmapWidth, croppedBitmapHeight);
|
|
|
|
|
|
|
|
// 旋转90度,让OCR可以识别
|
|
// 旋转90度,让OCR可以识别
|
|
|
Bitmap rotatedBitmap;
|
|
Bitmap rotatedBitmap;
|
|
@@ -405,9 +405,9 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
file.getParentFile().mkdirs();
|
|
file.getParentFile().mkdirs();
|
|
|
}
|
|
}
|
|
|
int max = rotatedBitmap.getWidth() > rotatedBitmap.getHeight() ? rotatedBitmap.getWidth() : rotatedBitmap.getHeight();
|
|
int max = rotatedBitmap.getWidth() > rotatedBitmap.getHeight() ? rotatedBitmap.getWidth() : rotatedBitmap.getHeight();
|
|
|
- int multi = 1;
|
|
|
|
|
|
|
+ float multi = 1.0f;
|
|
|
if (max > 1000) {
|
|
if (max > 1000) {
|
|
|
- multi = max / 1000 + 1;
|
|
|
|
|
|
|
+ multi = 1.0f * max / 1000 + 0.2f;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 压缩图片
|
|
// 压缩图片
|