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.
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.
Adjustments I made: SimpleMediaManager.Bas
Adjustments I made: SMMViews.Bas
And
example of operation in code:
Today we have a function to round the image "ROUNDIMAGE" which is very useful for user photos or even products.
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.
Adjustments I made: SimpleMediaManager.Bas
B4X:
Sub Class_Globals
...
Public Const REQUEST_CORNERSRADIUS = 0 As Int
...
End Sub
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
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
...
example of operation in code:
B4X:
mediaManager.SetMediaWithExtra(pnlImagem, link_imagem ,"image/*", CreateMap(mediaManager.REQUEST_RESIZE_MODE:"FILL_NO_DISTORTIONS", mediaManager.REQUEST_CORNERSRADIUS: 20dip))