From cf4cc22ce0342584a735dc101858bd9cd4964a3c Mon Sep 17 00:00:00 2001 From: Joshua Quick Date: Wed, 29 Apr 2020 08:39:18 -0700 Subject: [PATCH] fix(android): fix imageAsResized (#11667) Fixes TIMOB-27774 --- .../java/org/appcelerator/titanium/TiBlob.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiBlob.java b/android/titanium/src/java/org/appcelerator/titanium/TiBlob.java index c0774f2e8fb..c1baa9ff3f5 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiBlob.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiBlob.java @@ -6,6 +6,12 @@ */ package org.appcelerator.titanium; +import android.graphics.Bitmap; +import android.graphics.Bitmap.CompressFormat; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; +import android.media.ThumbnailUtils; +import android.util.Base64; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -14,7 +20,6 @@ import java.io.UnsupportedEncodingException; import java.net.URLConnection; import java.util.HashMap; - import org.appcelerator.kroll.KrollDict; import org.appcelerator.kroll.KrollProxy; import org.appcelerator.kroll.KrollRuntime; @@ -27,13 +32,6 @@ import org.appcelerator.titanium.util.TiImageHelper; import org.appcelerator.titanium.util.TiMimeTypeHelper; -import android.graphics.Bitmap; -import android.graphics.Bitmap.CompressFormat; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.media.ThumbnailUtils; -import android.util.Base64; - /** * A Titanium Blob object. A Blob can represent any opaque data or input stream. */ @@ -768,7 +766,10 @@ public TiBlob imageAsResized(Number width, Number height) imgWidth = img.getWidth(); imgHeight = img.getHeight(); if (rotation != 0) { + float scaleWidth = (float) dstWidth / imgWidth; + float scaleHeight = (float) dstHeight / imgHeight; Matrix matrix = new Matrix(); + matrix.postScale(scaleWidth, scaleHeight); matrix.postRotate(rotation); imageResized = Bitmap.createBitmap(img, 0, 0, imgWidth, imgHeight, matrix, true); } else {