I am going to create round image as per below link but I am getting the below error message. Please help to resolve this issues.
www.b4x.com
Error:-
B4A Version: 12.50
Parsing code. (0.11s)
Java Version: 8
Building folders structure. (0.03s)
Running custom action. (0.25s)
Compiling code. (0.85s)
Compiling layouts code. (0.02s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Compiling resources (0.23s)
Linking resources (1.32s)
Compiling generated Java code. Error
B4A line: 141
xIV.SetBitmap(CreateRoundBitmap(iv, xIV .Width))
javac 1.8.0_371
src\one\erp\productionentry.java:516: error: incompatible types: ImageView cannot be converted to Bitmap
_xiv.SetBitmap((android.graphics.Bitmap)(_createroundbitmap((anywheresoftware.b4a.objects.B4XViewWrapper.B4XBitmapWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.B4XViewWrapper.B4XBitmapWrapper(), (android.graphics.Bitmap)(_iv.getObject())),_xiv.getWidth()).getObject()));
Code :-
Sub CreateRoundBitmap (Input As B4XBitmap, Size As Int) As B4XBitmap
If Input.Width <> Input.Height Then
'if the image is not square then we crop it to be a square.
Dim l As Int = Min(Input.Width, Input.Height)
Input = Input.Crop(Input.Width / 2 - l / 2, Input.Height / 2 - l / 2, l, l)
End If
Dim c As B4XCanvas
Dim xview As B4XView = xui.CreatePanel("")
xview.SetLayoutAnimated(0, 0, 0, Size, Size)
c.Initialize(xview)
Dim path As B4XPath
path.InitializeOval(c.TargetRect)
c.ClipPath(path)
c.DrawBitmap(Input.Resize(Size, Size, False), c.TargetRect)
c.RemoveClip
c.DrawCircle(c.TargetRect.CenterX, c.TargetRect.CenterY, c.TargetRect.Width / 2 - 2dip, xui.Color_White, False, 5dip) 'comment this line to remove the border
c.Invalidate
Dim res As B4XBitmap = c.CreateBitmap
c.Release
Return res
End Sub
Sub DownloadImage(Link As String, iv As ImageView)
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Link)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
End If
j.Release
End Sub
[B4X] [XUI] Create a round image
Better implementation in B4XImageView (XUI Views) This code snippet is based on XUI library and it is compatible with B4A, B4i and B4J. The input is a bitmap and the output is a round bitmap (with no distortions). 'xui is a global XUI variable. Sub CreateRoundBitmap (Input As B4XBitmap...
Error:-
B4A Version: 12.50
Parsing code. (0.11s)
Java Version: 8
Building folders structure. (0.03s)
Running custom action. (0.25s)
Compiling code. (0.85s)
Compiling layouts code. (0.02s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Compiling resources (0.23s)
Linking resources (1.32s)
Compiling generated Java code. Error
B4A line: 141
xIV.SetBitmap(CreateRoundBitmap(iv, xIV .Width))
javac 1.8.0_371
src\one\erp\productionentry.java:516: error: incompatible types: ImageView cannot be converted to Bitmap
_xiv.SetBitmap((android.graphics.Bitmap)(_createroundbitmap((anywheresoftware.b4a.objects.B4XViewWrapper.B4XBitmapWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.B4XViewWrapper.B4XBitmapWrapper(), (android.graphics.Bitmap)(_iv.getObject())),_xiv.getWidth()).getObject()));
Code :-
Sub CreateRoundBitmap (Input As B4XBitmap, Size As Int) As B4XBitmap
If Input.Width <> Input.Height Then
'if the image is not square then we crop it to be a square.
Dim l As Int = Min(Input.Width, Input.Height)
Input = Input.Crop(Input.Width / 2 - l / 2, Input.Height / 2 - l / 2, l, l)
End If
Dim c As B4XCanvas
Dim xview As B4XView = xui.CreatePanel("")
xview.SetLayoutAnimated(0, 0, 0, Size, Size)
c.Initialize(xview)
Dim path As B4XPath
path.InitializeOval(c.TargetRect)
c.ClipPath(path)
c.DrawBitmap(Input.Resize(Size, Size, False), c.TargetRect)
c.RemoveClip
c.DrawCircle(c.TargetRect.CenterX, c.TargetRect.CenterY, c.TargetRect.Width / 2 - 2dip, xui.Color_White, False, 5dip) 'comment this line to remove the border
c.Invalidate
Dim res As B4XBitmap = c.CreateBitmap
c.Release
Return res
End Sub
Sub DownloadImage(Link As String, iv As ImageView)
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Link)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Round image:
Sub DownloadImage(Link As String, iv As ImageView)
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Link)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
iv.Bitmap = j.GetBitmap
Dim xIV As B4XView = iv
xIV.SetBitmap(CreateRoundBitmap(iv, xIV .Width))
End If
j.Release
End Sub
Sub CreateRoundBitmap (Input As B4XBitmap, Size As Int) As B4XBitmap
If Input.Width <> Input.Height Then
'if the image is not square then we crop it to be a square.
Dim l As Int = Min(Input.Width, Input.Height)
Input = Input.Crop(Input.Width / 2 - l / 2, Input.Height / 2 - l / 2, l, l)
End If
Dim c As B4XCanvas
Dim xview As B4XView = xui.CreatePanel("")
xview.SetLayoutAnimated(0, 0, 0, Size, Size)
c.Initialize(xview)
Dim path As B4XPath
path.InitializeOval(c.TargetRect)
c.ClipPath(path)
c.DrawBitmap(Input.Resize(Size, Size, False), c.TargetRect)
c.RemoveClip
c.DrawCircle(c.TargetRect.CenterX, c.TargetRect.CenterY, c.TargetRect.Width / 2 - 2dip, xui.Color_White, False, 5dip) 'comment this line to remove the border
c.Invalidate
Dim res As B4XBitmap = c.CreateBitmap
c.Release
Return res
End Sub
End If
j.Release
End Sub