Skip to content

Commit 53fadc5

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix scaling of layout bounds." into jb-dev
2 parents 8e8798d + 7634424 commit 53fadc5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

core/jni/android/graphics/BitmapFactory.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,15 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
304304
return nullObjectReturn("layoutBounds == null");
305305
}
306306

307-
env->SetIntArrayRegion(layoutBounds, 0, 4, (jint*) peeker.fLayoutBounds);
307+
jint scaledBounds[4];
308+
if (willScale) {
309+
for (int i=0; i<4; i++) {
310+
scaledBounds[i] = (jint)((((jint*)peeker.fLayoutBounds)[i]*scale) + .5f);
311+
}
312+
} else {
313+
memcpy(scaledBounds, (jint*)peeker.fLayoutBounds, sizeof(scaledBounds));
314+
}
315+
env->SetIntArrayRegion(layoutBounds, 0, 4, scaledBounds);
308316
if (javaBitmap != NULL) {
309317
env->SetObjectField(javaBitmap, gBitmap_layoutBoundsFieldID, layoutBounds);
310318
}

graphics/java/android/graphics/BitmapFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ private static Bitmap finishDecode(Bitmap bm, Rect outPadding, Options opts) {
556556
return bm;
557557
}
558558
byte[] np = bm.getNinePatchChunk();
559+
int[] lb = bm.getLayoutBounds();
559560
final boolean isNinePatch = np != null && NinePatch.isNinePatchChunk(np);
560561
if (opts.inScaled || isNinePatch) {
561562
float scale = targetDensity / (float) density;
@@ -569,6 +570,13 @@ private static Bitmap finishDecode(Bitmap bm, Rect outPadding, Options opts) {
569570
np = nativeScaleNinePatch(np, scale, outPadding);
570571
bm.setNinePatchChunk(np);
571572
}
573+
if (lb != null) {
574+
int[] newLb = new int[lb.length];
575+
for (int i=0; i<lb.length; i++) {
576+
newLb[i] = (int)((lb[i]*scale)+.5f);
577+
}
578+
bm.setLayoutBounds(newLb);
579+
}
572580
}
573581

574582
bm.setDensity(targetDensity);

0 commit comments

Comments
 (0)