Wish Add CORNERS RADIUS in [B4X] SimpleMediaManager (SMM)

Lucas Siqueira

Active Member
Licensed User
Longtime User
Please @Erel , I know you don't like exclusive posts, but this is a case of adjusting the source code of your [B4X] SimpleMediaManager (SMM) library which is fantastic. Congrats on it!

Today we have a function to round the image "ROUNDIMAGE" which is very useful for user photos or even products.

1751382830521.png


But when we put pictures of food or landscapes, it would be better to put images with rounded corners "CORNERSRADIUS" and not completely round "ROUNDIMAGE".

When possible, add the rounded corners function to the Simple Media Manager class. I managed to make an adjustment here using part of the code from (UpdateClip) B4XImageView.bas and would like to share it with you to help further improve your library that makes B4X development the best IDE for mobile.

Note: I know I could run the CreateMap(MediaManager.REQUEST_CALLBACK: Me) command, wait for the image to return Wait For (Pane1) SMM_MediaReady (Success As Boolean, Media As SMMedia), and then round it in a B4XImageView, but it is much simpler and more practical if we can already define the rounded corner in the request itself, as the round image is defined.

1751382743120.png


Adjustments I made: SimpleMediaManager.Bas

B4X:
Sub Class_Globals
...
Public Const REQUEST_CORNERSRADIUS = 0 As Int
...
End Sub
1751383267412.png


Adjustments I made: SMMViews.Bas
B4X:
Private Sub UpdateClip(mBase As B4XView, mCornersRadius As Int)
    mBase.SetColorAndBorder(mBase.Color, 0, 0, mCornersRadius)
#if B4J
    Dim jo As JavaObject = mBase
    Dim shape As JavaObject
    Dim cx As Double = mBase.Width
    Dim cy As Double = mBase.Height
    shape.InitializeNewInstance("javafx.scene.shape.Rectangle", Array(cx, cy))
    If mCornersRadius > 0 Then
        Dim d As Double = mCornersRadius
        shape.RunMethod("setArcHeight", Array(d))
        shape.RunMethod("setArcWidth", Array(d))
    End If
    jo.RunMethod("setClip", Array(shape))
#else if B4A
    Dim jo As JavaObject = mBase
    jo.RunMethod("setClipToOutline", Array(mCornersRadius > 0))
#end if
End Sub
1751383517555.png



And

B4X:
Public Sub AddMedia(RequestSet As SMMediaRequestSet, MEDIA As SMMedia, Request As SMMediaRequest)
...
Select ViewType
        Case VIEW_TYPE_B4XIMAGEVIEW
            ...
            Dim cornerRadius As Int = Request.Extra.GetDefault(mManager.REQUEST_CORNERSRADIUS,0)
            If cornerRadius > 0 And x.RoundedImage = False Then
                UpdateClip(x.mBase, cornerRadius)
            End If
         ...
1751383469710.png



example of operation in code:
B4X:
mediaManager.SetMediaWithExtra(pnlImagem, link_imagem ,"image/*", CreateMap(mediaManager.REQUEST_RESIZE_MODE:"FILL_NO_DISTORTIONS", mediaManager.REQUEST_CORNERSRADIUS: 20dip))
 

Attachments

  • SimpleMediaManager.bas
    24.4 KB · Views: 47
  • SMMViews.bas
    13 KB · Views: 47

Cableguy

Expert
Licensed User
Longtime User
B4XLibs and .Bas modules are considered as Open Source, if not specified otherwise.
This means you are free to add to those Libs/Modules and share back to the forum, giving proper credits to the original author, and changing the version number accordingly. You can/should even share it in the same thread that was used to introduce the lib/module or ask the author to add it to the first post...
This is one of the beautiful aspects of this platform
 

Lucas Siqueira

Active Member
Licensed User
Longtime User
B4XLibs and .Bas modules are considered as Open Source, if not specified otherwise.
This means you are free to add to those Libs/Modules and share back to the forum, giving proper credits to the original author, and changing the version number accordingly. You can/should even share it in the same thread that was used to introduce the lib/module or ask the author to add it to the first post...
This is one of the beautiful aspects of this platform
I'll leave the modified library here, but it would be great if the code was implemented in the official Erel library, and not have a parallel library.

- v1.18 - Rounds the corners of the image when loaded. This is done with the new extra field REQUEST_CORNERSRADIUS, default value is 0.
 

Attachments

  • SimpleMediaManagerMOD.b4xlib
    24.7 KB · Views: 45

Cableguy

Expert
Licensed User
Longtime User
Then ask EREL to move it to the additional libs sub-forum, and change the title.
As it stands, no one will find it, nor see that it is an addition to the original lib.
 

TILogistic

Expert
Licensed User
Longtime User
Note:
I made this request a while ago, as you can see in this post, and the solution I used was external to the library.

1.gif
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

TILogistic

Expert
Licensed User
Longtime User
Note that this applies to images uploaded to media, but does not apply to the default error image.
B4X:
    Extra.Put(SimpleMediaManager1.REQUEST_ROUNDIMAGE, False) 'Only Extras default False
    Extra.Put(SimpleMediaManager1.REQUEST_CORNERS_RADIUS, 30) 'Only Extras default 0
image error:
B4X:
    SimpleMediaManager1.AddLocalMedia(SimpleMediaManager1.KEY_DEFAULT_ERROR, xui.LoadBitmap(File.DirAssets, "error.png"), "image/*")
ex.
1751444720373.png


I commented on this in the post #6.
 
Last edited:

TILogistic

Expert
Licensed User
Longtime User
Yes, it works. It was my mistake. The error image had a transparent background.
Thanks.

B4X:
    SimpleMediaManager1.DefaultErrorRequest.Extra.Put(SimpleMediaManager1.REQUEST_CORNERS_RADIUS, 30dip)
    SimpleMediaManager1.DefaultErrorRequest.Extra.Put(SimpleMediaManager1.REQUEST_BACKGROUND, xui.Color_White)
1751523757617.png
 

Lucas Siqueira

Active Member
Licensed User
Longtime User
Done: https://www.b4x.com/android/forum/t...rk-for-images-videos-and-more.134716/#content

Note that as B4XImageView already supports this feature, it was a matter of adding a single line (and the constant itself):
B4X:
x.CornersRadius = Request.Extra.GetDefault(mManager.REQUEST_CORNERS_RADIUS, 0)

@Erel This new feature in the rounded corners library for images is wonderful, but I still have one more suggestion.

Add the DefaultCornersRadius mode

With the default field, the command to load the image would be even simpler. Instead of having to create a map and load it with SetMediaWithExtra, we could use the simple SetMedia command.

- v1.19 - New DefaultCornersRadius mode. Sets the images corners radius.




Adjustments I made: SimpleMediaManager.Bas
B4X:
Sub Class_Globals
...
Public DefaultCornersRadius As Int = 0
...
End Sub
1751543309677.png



Adjustments I made: SMMViews.Bas
B4X:
Public Sub AddMedia(RequestSet As SMMediaRequestSet, MEDIA As SMMedia, Request As SMMediaRequest)
    ...
    Select ViewType
        Case VIEW_TYPE_B4XIMAGEVIEW
        ...
        x.CornersRadius = Request.Extra.GetDefault(mManager.REQUEST_CORNERS_RADIUS, mManager.DefaultCornersRadius)    
        ...
End Sub
1751543375660.png
 

Attachments

  • SimpleMediaManager.b4xlib
    24.6 KB · Views: 35
Top