Android Question Radius for Imageview

stevenindon

Active Member
Licensed User
Hello all,

I have put an image to a Imageview (Dim as B4xview). But when i try to set the radius of the imageview with the followings:

MyImageView.SetColorAndBorder(xui.Color_White,1dip,xui.Color_Blue,30dip)

I got the radius drawn on the image view...but the image became white. I even tried :

MyImageView.SetColorAndBorder(xui.Color_Transparent,1dip,xui.Color_Blue,30dip)... now the image is lost.

How can I set the radius of the imageview but maintain the image?

Thanks
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
Use B4XImageview from Xui Views. Its easy to set radius, as well as resize modes

 
Upvote 1

stevenindon

Active Member
Licensed User
Mcqueccu, Thank you for your suggestion. I can't use B4XImageview as my Imageview are created using codes (Arrays of Imageview) that are then inserted into Customlistview as 'cards'

I need to find a way to make my imageview with images to have certain degree of radius. With this code :

MyImageView.SetColorAndBorder(xui.Color_Transparent,1dip,xui.Color_Blue,30dip)

IOS runs without problem (Imageview displays image with radius)... but not in Android.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
? B4X
B4X:
    Dim img As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "1.png", ImageView1.Width, ImageView1.Height, True)
    ImageView1.SetBitmap(CreateRoundRectBitmap(img, 20dip))
B4X:
Public Sub CreateRoundRectBitmap (Input As B4XBitmap, Radius As Float) As B4XBitmap
    Dim BorderColor As Int = xui.Color_Black
    Dim BorderWidth As Int = 4dip
    Dim c As B4XCanvas
    Dim xview As B4XView = xui.CreatePanel("")
    xview.SetLayoutAnimated(0, 0, 0, Input.Width, Input.Height)
    c.Initialize(xview)
    Dim path As B4XPath
    path.InitializeRoundedRect(c.TargetRect, Radius)
    c.ClipPath(path)
    c.DrawRect(c.TargetRect, BorderColor, True, BorderWidth) 'border
    c.RemoveClip
    Dim r As B4XRect
    r.Initialize(BorderWidth, BorderWidth, c.TargetRect.Width - BorderWidth, c.TargetRect.Height - BorderWidth)
    path.InitializeRoundedRect(r, Radius - 0.7 * BorderWidth)
    c.ClipPath(path)
    c.DrawBitmap(Input, r)
    c.RemoveClip
    c.Invalidate
    Dim res As B4XBitmap = c.CreateBitmap
    c.Release
    Return res
End Sub

1643772298926.png


See:
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Other:
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Mcqueccu, Thank you for your suggestion. I can't use B4XImageview as my Imageview are created using codes (Arrays of Imageview) that are then inserted into Customlistview as 'cards'
Best to use B4XImageView. It will have much better performance compared to the code above.
You can create any custom view programmatically: [B4X] I need 100 <custom view here>s. How to add programmatically?
B4XImageView is especially simple to create with:
B4X:
Dim iv As B4XImageView = XUIViewsUtils.CreateB4XImageView
 
Upvote 0
Top