|
@@ -346,7 +346,29 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
int croppedBitmapWidth;
|
|
int croppedBitmapWidth;
|
|
|
int croppedBitmapHeight;
|
|
int croppedBitmapHeight;
|
|
|
|
|
|
|
|
- //boolean isLandscape = mBottom-mTop > mRight-mLeft;
|
|
|
|
|
|
|
+ // 经过试验,满屏宽总是与图片的宽完全对应,所以无论如何都要以宽为基准
|
|
|
|
|
+ if (rawBitmapWidth >= mWidth) {
|
|
|
|
|
+ // 图片宽比屏幕的宽大,拿图片缩小,缩小为原宽除以pivot
|
|
|
|
|
+ float pivot = 1.0f * rawBitmapWidth / mWidth;
|
|
|
|
|
+ //float scaledHeight = rawBitmapHeight / pivot;
|
|
|
|
|
+ //if (scaledHeight > )
|
|
|
|
|
+ realLeft = (int) (mLeft * pivot);
|
|
|
|
|
+ realTop = (int) (mTop * pivot);
|
|
|
|
|
+ croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
|
|
+ croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 图片宽比屏幕的宽小,拿图片放大,放大为原宽乘以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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /*//boolean isLandscape = mBottom-mTop > mRight-mLeft;
|
|
|
|
|
|
|
|
// 图片宽度与屏幕宽度的比
|
|
// 图片宽度与屏幕宽度的比
|
|
|
float widthD = 1.0f * rawBitmapWidth / mWidth;
|
|
float widthD = 1.0f * rawBitmapWidth / mWidth;
|
|
@@ -360,7 +382,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
// 图片宽要缩小到屏幕宽
|
|
// 图片宽要缩小到屏幕宽
|
|
|
float pivot = 1.0f * rawBitmapWidth / mWidth;
|
|
float pivot = 1.0f * rawBitmapWidth / mWidth;
|
|
|
realLeft = (int) (mLeft * pivot);
|
|
realLeft = (int) (mLeft * pivot);
|
|
|
- realTop = (int) (mTop * pivot) + (rawBitmapHeight-mHeight)/2;
|
|
|
|
|
|
|
+ realTop = (int) (mTop * pivot) + (int)(((rawBitmapHeight/pivot-mHeight)/2)*pivot);
|
|
|
croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
|
|
croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
|
|
croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
|
|
|
} else {
|
|
} else {
|
|
@@ -377,8 +399,8 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
if (heightD >= 1) {
|
|
if (heightD >= 1) {
|
|
|
// 以高为基准
|
|
// 以高为基准
|
|
|
// 图片高要缩小到屏幕高,缩小了pivot倍
|
|
// 图片高要缩小到屏幕高,缩小了pivot倍
|
|
|
- float pivot = 1.0f * rawBitmapHeight / mHeight;
|
|
|
|
|
- realLeft = (int) (mLeft * pivot) + (rawBitmapWidth-mWidth)/2;
|
|
|
|
|
|
|
+ float pivot = 1.0f * rawBitmapWidth / mWidth;
|
|
|
|
|
+ realLeft = (int) (mLeft * pivot) + (int)((rawBitmapWidth/pivot - mWidth)/2*pivot);
|
|
|
realTop = (int) (mTop * pivot);
|
|
realTop = (int) (mTop * pivot);
|
|
|
croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
|
|
croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
|
|
|
croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
|
|
croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
|
|
@@ -391,7 +413,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
croppedBitmapWidth = (int) (1.0f * (mRight - mLeft)/pivot);
|
|
croppedBitmapWidth = (int) (1.0f * (mRight - mLeft)/pivot);
|
|
|
croppedBitmapHeight = (int) (1.0f * (mBottom - mTop)/pivot);
|
|
croppedBitmapHeight = (int) (1.0f * (mBottom - mTop)/pivot);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
|
|
|
|
Bitmap croppedBmp = Bitmap.createBitmap(normalBitmap, realLeft, realTop, croppedBitmapWidth, croppedBitmapHeight);
|
|
Bitmap croppedBmp = Bitmap.createBitmap(normalBitmap, realLeft, realTop, croppedBitmapWidth, croppedBitmapHeight);
|
|
@@ -425,7 +447,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
rotatedBitmap.recycle();
|
|
rotatedBitmap.recycle();
|
|
|
if (saveCropSuccess) {
|
|
if (saveCropSuccess) {
|
|
|
File compressedFile = new Compressor(context.getApplicationContext())
|
|
File compressedFile = new Compressor(context.getApplicationContext())
|
|
|
- .setQuality(98)
|
|
|
|
|
|
|
+ .setQuality(97)
|
|
|
.setDestinationDirectoryPath(file.getParentFile().getAbsolutePath())
|
|
.setDestinationDirectoryPath(file.getParentFile().getAbsolutePath())
|
|
|
.compressToFile(file, "cp_" + file.getName());
|
|
.compressToFile(file, "cp_" + file.getName());
|
|
|
|
|
|