diff --git a/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ETImage.kt b/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ETImage.kt index 02e11532..4dcb646f 100644 --- a/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ETImage.kt +++ b/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ETImage.kt @@ -78,6 +78,7 @@ class ETImage( rgbValues[(y * width + x) + 2 * height * width] = blue.toByte() } } + bitmap.recycle() return rgbValues } catch (e: FileNotFoundException) { throw RuntimeException(e) @@ -87,15 +88,21 @@ class ETImage( private fun resizeImage(uri: Uri, sideSize: Int): Bitmap? { val inputStream = contentResolver.openInputStream(uri) if (inputStream == null) { - ETLogging.getInstance().log("Unable to resize image, input streams is null") + ETLogging.getInstance().log("Unable to resize image, input stream is null") return null } - val bitmap = BitmapFactory.decodeStream(inputStream) + val bitmap = inputStream.use { + BitmapFactory.decodeStream(it) + } if (bitmap == null) { ETLogging.getInstance().log("Unable to resize image, bitmap during decode stream is null") return null } - - return Bitmap.createScaledBitmap(bitmap, sideSize, sideSize, false) + val scaled = Bitmap.createScaledBitmap(bitmap, sideSize, sideSize, true) // ← bilinear + if (scaled !== bitmap) { + bitmap.recycle() + } + return scaled } + }