Android Question XUI - B4XCanvas

Discussion in 'Android Questions' started by LucaMs, Mar 4, 2018.

  1. LucaMs

    LucaMs Expert Licensed User

  2. Erel

    Erel Administrator Staff Member Licensed User

    It is set internally.
     
  3. LucaMs

    LucaMs Expert Licensed User

    Are you sure? Is it set correctly?

    upload_2018-3-4_10-37-32.png

    On the left, the standard canvas, with anti aliasing.
    On the right, XUICanvas (code snippet mentioned in the first post).
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It probably happens because of the clipping. Try to draw a circle with B4XCanvas.
     
  5. LucaMs

    LucaMs Expert Licensed User

    Yes, it is the clipping. DrawBitmap also has this problem:
    upload_2018-3-4_10-56-0.png

    Left: standard canvas
    Center: the snippet
    Right: B4XCanvas DrawCircle
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You should compare it to clipping with the standard canvas. The result should be the same.
     
  7. LucaMs

    LucaMs Expert Licensed User

    You make me work too much! :D

    Does this mean that clipping (standard or XUI) has this problem?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    This is not exactly a problem. You need to understand how anti aliasing works...

    The way to solve it in this case is to draw the circle after you remove the clipping.
     
  9. LucaMs

    LucaMs Expert Licensed User

    But the bitmap will be drawn anyway without anti-aliasing... or not?
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    The issue with the bitmap drawing is not related to anti aliasing but rather to the way the bitmap is resized.

    This code should provide better results:
    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(
    000, 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, False5dip'comment this line to remove the border
       c.Invalidate
       
    Dim res As B4XBitmap = c.CreateBitmap
       c.Release
       
    Return res
    End Sub
     
    LucaMs likes this.
  11. LucaMs

    LucaMs Expert Licensed User

    Much better!
     
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