Hi All!
I'm picked up some pieces of codes here in forum and trying to develop a Sub that can apply a round filter in ImageView.
I'm using this code.
My problem is... In most cases, my picture are in Base64 format. And after convert to input stream, I can use this code. But, in some cases I have different behaviours. The final picture gets smaller than the ImageView size, and also, in some cases, I got the final image bigger than the image view.
So, how can I solve that issue, once I need to maintain the final picture limited of ImageView size?
Thanks.
I'm picked up some pieces of codes here in forum and trying to develop a Sub that can apply a round filter in ImageView.
I'm using this code.
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)
Dim cvs As Canvas = CreateBitmap(p.Width, p.Height)
DrawRoundBitmap(cvs, p)
Return cvs.Bitmap
Catch
Dim p As Bitmap
p.Initialize(File.DirAssets, "avatar-scholastic.png")
Dim cvs As Canvas = CreateBitmap(p.Width, p.Height)
DrawRoundBitmap(cvs, p)
Return cvs.Bitmap
End Try
End Sub
Public Sub roundImage(Img As Bitmap) As Bitmap
Dim cvs As Canvas = CreateBitmap(Img.Width, Img.Height)
DrawRoundBitmap(cvs, Img)
Return cvs.Bitmap
End Sub
Private Sub CreateBitmap(w As Long, h As Long) As Canvas
Dim bmp As Bitmap
bmp.InitializeMutable(w, h)
Dim cvs As Canvas
cvs.Initialize2(bmp)
Dim r As Rect
r.Initialize(0, 0, bmp.Width, bmp.Height)
cvs.DrawRect(r, Colors.Transparent, True, 0)
Dim p As Path
p.Initialize(0, 0)
Dim jo As JavaObject = p
Dim x = 100dip, y = 100dip, radius = 100dip As Float
jo.RunMethod("addCircle", Array As Object(x, y, radius, "CW"))
cvs.ClipPath(p)
Return cvs
End Sub
Private Sub DrawRoundBitmap (cvs As Canvas, bmp As Bitmap)
Dim r As Rect
r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
cvs.DrawBitmap(bmp, Null, r)
End Sub
My problem is... In most cases, my picture are in Base64 format. And after convert to input stream, I can use this code. But, in some cases I have different behaviours. The final picture gets smaller than the ImageView size, and also, in some cases, I got the final image bigger than the image view.
So, how can I solve that issue, once I need to maintain the final picture limited of ImageView size?
Thanks.