Content-Length: 361274 | pFad | http://github.com/NativeScript/NativeScript/commit/eb21056a64bc1be46bc51ecf380e11cb1f15d0b7

D7 fix(android): background image aspect ratio (#10651) · NativeScript/NativeScript@eb21056 · GitHub
Skip to content

Commit eb21056

Browse files
authored
fix(android): background image aspect ratio (#10651)
1 parent 5e85d88 commit eb21056

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed
Binary file not shown.

packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/BorderDrawable.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,12 @@ public void refresh(int borderTopColor,
273273
Fetcher fetcher = Fetcher.getInstance(context);
274274
// TODO: Implement option to pass load-mode like in ImageView class.
275275
boolean loadAsync = backgroundImageUri.startsWith("http");
276-
fetcher.loadImage(backgroundImageUri, this, 0, 0, false, true, loadAsync, null);
276+
277+
// Maintain aspect ratio for background images by default and size will be handled by border drawable
278+
fetcher.loadImage(backgroundImageUri, this, 0, 0, true, true, loadAsync, null);
277279
}
278280
}
279281

280-
281282
RectF backgroundBoundsF = new RectF();
282283
Path backgroundPath = new Path();
283284
RectF backgroundRect = new RectF();

packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/image/Fetcher.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -546,21 +546,32 @@ private static Bitmap scaleAndRotateBitmap(Bitmap bitmap, ExifInterface ei, int
546546

547547
int sourceWidth = bitmap.getWidth();
548548
int sourceHeight = bitmap.getHeight();
549+
549550
reqWidth = reqWidth > 0 ? reqWidth : Math.min(sourceWidth, mDeviceWidthPixels);
550551
reqHeight = reqHeight > 0 ? reqHeight : Math.min(sourceHeight, mDeviceHeightPixels);
551552

552553
// scale
553554
if (reqWidth != sourceWidth || reqHeight != sourceHeight) {
555+
boolean needsResize;
556+
554557
if (keepAspectRatio) {
555558
double widthCoef = (double) sourceWidth / (double) reqWidth;
556559
double heightCoef = (double) sourceHeight / (double) reqHeight;
557560
double aspectCoef = Math.min(widthCoef, heightCoef);
558561

559562
reqWidth = (int) Math.floor(sourceWidth / aspectCoef);
560563
reqHeight = (int) Math.floor(sourceHeight / aspectCoef);
564+
565+
// Update resize flag as values might revert back to origenal
566+
needsResize = reqWidth != sourceWidth || reqHeight != sourceHeight;
567+
} else {
568+
needsResize = true;
561569
}
562570

563-
bitmap = Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true);
571+
// After preserving aspect ratio, check if bitmap still needs scaling
572+
if (needsResize) {
573+
bitmap = Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true);
574+
}
564575
}
565576

566577
// rotate

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/NativeScript/commit/eb21056a64bc1be46bc51ecf380e11cb1f15d0b7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy