File tree Expand file tree Collapse file tree
llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,15 +87,21 @@ class ETImage(
8787 private fun resizeImage (uri : Uri , sideSize : Int ): Bitmap ? {
8888 val inputStream = contentResolver.openInputStream(uri)
8989 if (inputStream == null ) {
90- ETLogging .getInstance().log(" Unable to resize image, input streams is null" )
90+ ETLogging .getInstance().log(" Unable to resize image, input stream is null" )
9191 return null
9292 }
93- val bitmap = BitmapFactory .decodeStream(inputStream)
93+ val bitmap = inputStream.use {
94+ BitmapFactory .decodeStream(it)
95+ }
9496 if (bitmap == null ) {
9597 ETLogging .getInstance().log(" Unable to resize image, bitmap during decode stream is null" )
9698 return null
9799 }
98-
99- return Bitmap .createScaledBitmap(bitmap, sideSize, sideSize, false )
100+ val scaled = Bitmap .createScaledBitmap(bitmap, sideSize, sideSize, true ) // ← bilinear
101+ if (scaled != = bitmap) {
102+ bitmap.recycle()
103+ }
104+ return scaled
100105 }
106+
101107}
You can’t perform that action at this time.
0 commit comments