Android Question Change bitmap size

Carles Escudé

Member
Licensed User
Longtime User
Hello!

I have a source bitmap sized 300x200 and I want to load it in another bitmap sized 150x100

Ofcourse I want to resize it. Not cutted

How can I do it?

Thanks
 

Carles Escudé

Member
Licensed User
Longtime User
Don't know if there is a better solution, but I did it! :)

B4X:
Sub changeImageSize(bmp As Bitmap, destWidth As Int, destHeight As Int) As Bitmap
    Private imv As ImageView
    Private cvs As Canvas
    Dim pnl As Panel
    pnl.Initialize("pnl")
    imv.Initialize("imv")
    pnl.AddView(imv,0,0,bmp.Width,bmp.Height)
    cvs.Initialize(imv)   
   
    Dim rSrc As Rect
    Dim rDest As Rect
   
    rSrc.Initialize(0, 0, bmp.Width, bmp.Height)
    rDest.Initialize(0, 0, destWidth*2, destHeight/2)
    cvs.DrawBitmap(bmp, rSrc, rDest)
   
    imv.Invalidate   
   
    Return imv.Bitmap
End Sub
 
Upvote 0

Carles Escudé

Member
Licensed User
Longtime User
No. I do not load it in a image view. I am loading it in a xnGridCol.

I have tried to set the gravity of the column to "Fill" but it don't change anyting.

Thanks;)
 
Upvote 0
Top