Wish: Implement createScaledBitmap

Widget

Well-Known Member
Licensed User
Longtime User
I'd like to be able to use: android.graphics.Bitmap.createScaledBitmap
to scale a bitmap using new dimensions. It would be much easier than trying to do it myself and I'd likely get better results. ;)

B4X:
createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
Creates a new bitmap, scaled from an existing bitmap.

See Bitmap | Android Developers

Widget
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here is an implementation done with JavaObject library:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim b As Bitmap
   b = LoadBitmap(File.DirAssets, "small_logo.png")
   b = CreateScaledBitmap(b, 16, 16, True)
End Sub

Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, Filter As Boolean) As Bitmap
  Dim jo As JavaObject
  jo.InitializeStatic("android.graphics.Bitmap")
  Return jo.RunMethod("createScaledBitmap", Array (Original, Width, Height, Filter))
End Sub
 
Last edited:

Widget

Well-Known Member
Licensed User
Longtime User
Seems to be similar to LoadBitmapSample.
Here is an implementation done with the Reflection library:

Erel,
Your CreateScaledBitmap() routine is a real life saver. :sign0060:

The effects of CreateScaledBitmap() are similiar to LoadBitmapSample if displaying the bitmap in an ImageView. But ImageView.LoadBitmapSample and Bitmap.InitializeSample WON'T create bitmaps anywhere near the size I specified in the parameter list.

But CreateScaledBitmap() creates a bitmap of the size I specified, which is great. Also when the Filter parameter is True, it does a good job of anti-aliasing the image (up sizing or down sizing) so it looks as smooth as an ImageView. The CreateScaledBitmap() also allows me to resize bitmaps that have already been loaded into memory so it does not have to go back to disk.

So you made my day and I owe you a beer for this one. :sign0098:

Widget
 
Top