mirror of
https://gitee.com/shuto/customCamera.git
synced 2026-05-02 00:07:24 +08:00
Fix bug: the overlay picture was not resized when it is smaller than the screen even with displayMetrics.density.
This commit is contained in:
@@ -40,20 +40,18 @@ public class BitmapUtils {
|
|||||||
int displayHeightPx = (int) displayMetrics.heightPixels;
|
int displayHeightPx = (int) displayMetrics.heightPixels;
|
||||||
// Get picture.
|
// Get picture.
|
||||||
Options options = BitmapUtils.determineOriginalSizePicture(data);
|
Options options = BitmapUtils.determineOriginalSizePicture(data);
|
||||||
int widthResize = 0;
|
|
||||||
int heightResize = 0;
|
|
||||||
int widthBackground = (int) (options.outWidth * displayMetrics.density);
|
int widthBackground = (int) (options.outWidth * displayMetrics.density);
|
||||||
int heightBackground= (int) (options.outHeight * displayMetrics.density);
|
int heightBackground= (int) (options.outHeight * displayMetrics.density);
|
||||||
float ratioX = (float) widthBackground / (float) displayWidthPx;
|
float ratioX = (float) widthBackground / (float) displayWidthPx;
|
||||||
float ratioY = (float) heightBackground / (float) displayHeightPx;
|
float ratioY = (float) heightBackground / (float) displayHeightPx;
|
||||||
int inSampleSize = 1;
|
int inSampleSize = 1;
|
||||||
if (ratioX > ratioY && ratioX > 1) {
|
if (ratioX > ratioY && ratioX > 1) {
|
||||||
widthResize = (int) displayWidthPx;
|
widthBackground = (int) displayWidthPx;
|
||||||
heightResize = (int) (heightBackground / ratioX);
|
heightBackground = (int) (heightBackground / ratioX);
|
||||||
inSampleSize = (int) ratioX;
|
inSampleSize = (int) ratioX;
|
||||||
} else if (ratioX <= ratioY && ratioY > 1) {
|
} else if (ratioX <= ratioY && ratioY > 1) {
|
||||||
widthResize = (int) (widthBackground / ratioY);
|
widthBackground = (int) (widthBackground / ratioY);
|
||||||
heightResize = (int) displayHeightPx;
|
heightBackground = (int) displayHeightPx;
|
||||||
inSampleSize = (int) ratioY;
|
inSampleSize = (int) ratioY;
|
||||||
}
|
}
|
||||||
options.inSampleSize = inSampleSize;
|
options.inSampleSize = inSampleSize;
|
||||||
@@ -61,9 +59,7 @@ public class BitmapUtils {
|
|||||||
|
|
||||||
Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length, options);
|
Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length, options);
|
||||||
data = null;
|
data = null;
|
||||||
if (widthResize > 0 && heightResize > 0) {
|
picture = Bitmap.createScaledBitmap(picture, widthBackground, heightBackground, true);
|
||||||
picture = Bitmap.createScaledBitmap(picture, widthResize, heightResize, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return picture;
|
return picture;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user