mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 10:01:08 +08:00
fix(android): background image aspect ratio (#10651)
This commit is contained in:

committed by
GitHub

parent
5e85d8873c
commit
eb21056a64
Binary file not shown.
@ -273,10 +273,11 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
||||
Fetcher fetcher = Fetcher.getInstance(context);
|
||||
// TODO: Implement option to pass load-mode like in ImageView class.
|
||||
boolean loadAsync = backgroundImageUri.startsWith("http");
|
||||
fetcher.loadImage(backgroundImageUri, this, 0, 0, false, true, loadAsync, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Maintain aspect ratio for background images by default and size will be handled by border drawable
|
||||
fetcher.loadImage(backgroundImageUri, this, 0, 0, true, true, loadAsync, null);
|
||||
}
|
||||
}
|
||||
|
||||
RectF backgroundBoundsF = new RectF();
|
||||
Path backgroundPath = new Path();
|
||||
|
@ -546,11 +546,14 @@ public class Fetcher extends Worker {
|
||||
|
||||
int sourceWidth = bitmap.getWidth();
|
||||
int sourceHeight = bitmap.getHeight();
|
||||
|
||||
reqWidth = reqWidth > 0 ? reqWidth : Math.min(sourceWidth, mDeviceWidthPixels);
|
||||
reqHeight = reqHeight > 0 ? reqHeight : Math.min(sourceHeight, mDeviceHeightPixels);
|
||||
|
||||
// scale
|
||||
if (reqWidth != sourceWidth || reqHeight != sourceHeight) {
|
||||
boolean needsResize;
|
||||
|
||||
if (keepAspectRatio) {
|
||||
double widthCoef = (double) sourceWidth / (double) reqWidth;
|
||||
double heightCoef = (double) sourceHeight / (double) reqHeight;
|
||||
@ -558,10 +561,18 @@ public class Fetcher extends Worker {
|
||||
|
||||
reqWidth = (int) Math.floor(sourceWidth / aspectCoef);
|
||||
reqHeight = (int) Math.floor(sourceHeight / aspectCoef);
|
||||
|
||||
// Update resize flag as values might revert back to original
|
||||
needsResize = reqWidth != sourceWidth || reqHeight != sourceHeight;
|
||||
} else {
|
||||
needsResize = true;
|
||||
}
|
||||
|
||||
// After preserving aspect ratio, check if bitmap still needs scaling
|
||||
if (needsResize) {
|
||||
bitmap = Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true);
|
||||
}
|
||||
}
|
||||
|
||||
// rotate
|
||||
if (ei != null) {
|
||||
|
Reference in New Issue
Block a user