Android Question Create a round image from imagedownloader service

Discussion in 'Android Questions' started by hanyelmehy, Aug 26, 2019.

  1. hanyelmehy

    hanyelmehy Active Member Licensed User

    i use imagedownloader service to download image ,i need to return rounded image from service
    next code must call from activity ,any other solution can work in service

    Code:
    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(
    000, 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
     
  2. lucasheer

    lucasheer Member Licensed User

    Since the imagedownloader doesn't directly give you the bitmap, just call the CreateRoundRectBitmap method on the ImageView's bitmap afterwards:

    Code:
    Dim myImage As ImageView = roundedImageView
    links.Put(myImage, 
    "http://www.basic4ppc.com/basic4android/images/SS-2012-08-29_12.55.42.png")
    myImage.Bitmap = CreateRoundBitmap(myImage.Bitmap, 
    40dip)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice