Hi All.
I'm trying to use this code snippet to resize an image, but I don't have success. What's am I doing wrong?
I'm trying to use this code snippet to resize an image, but I don't have success. What's am I doing wrong?
B4X:
Public Sub loadPhoto(photo As String) As Bitmap
Try
Dim su As StringUtils
Dim i As InputStream
i.InitializeFromBytesArray(su.DecodeBase64(photo), 0, su.DecodeBase64(photo).Length)
Dim p As Bitmap
p.Initialize2(i)
Return p
Catch
Dim p As Bitmap
p.Initialize(File.DirAssets, "avatar-scholastic.png")
Return p
End Try
End Sub
Public Sub ResizeImage (Image As String, Scale As Int) As Bitmap
Dim PhotoCanvas As Canvas
Dim PhotoPanel As Panel
Dim PhotoView As ImageView
Dim NewImage As Bitmap
PhotoView.Initialize("")
PhotoView.Bitmap = loadPhoto(Image)
PhotoPanel.Initialize("")
PhotoPanel.Height = 500
PhotoPanel.Width = 500
PhotoPanel.SetBorder(0, Colors.Transparent, PhotoView.Width/2)
PhotoPanel.AddView(PhotoView,0,0, PhotoPanel.Width / Scale, PhotoPanel.Height / Scale)
PhotoCanvas.Initialize(PhotoPanel)
NewImage = PhotoCanvas.CreateBitmap
Return NewImage
End Sub