Android Question Flip image with SimpleMediaManager

angel_

Well-Known Member
Licensed User
I am using SimpleMediaManager and it works great, how can I flip an image after loading with SetMediaFromFile? I am using a temporary file there is another alternative (for B4A and B4i).

I have this code:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    MediaManager.Initialize
End Sub

Private Sub Button1_Click
    MediaManager.SetMediaFromFile(Panel1, File.DirAssets, "img.png", "image/*", Null)
End Sub

Private Sub Button2_Click
    FlipHorizontal
End Sub

Private Sub FlipHorizontal
    Dim bmp As B4XBitmap
    Dim bmp_flip As B4XBitmap
    Dim effect As BitmapCreatorEffects
    
    bmp = Panel1.Snapshot
    
    effect.Initialize
    bmp_flip = effect.FlipHorizontal(bmp)
    
    Dim Out As OutputStream
    Out = File.OpenOutput(xui.DefaultFolder, "TempFlip.png", False)
    bmp_flip.WriteToStream(Out, 100, "PNG")
    Out.Close
    
    MediaManager.SetMediaFromFile(Panel1,xui.DefaultFolder, "TempFlip.png", "image/*", Null)
End Sub
 

Attachments

  • FlipMedia.zip
    19.4 KB · Views: 69
Solution
The image quality is lost when you call Panel.Snapshot as the panel is smaller than the original bitmap.

You should instead access the B4XImageView that was added to the panel:
B4X:
bmp = Panel1.GetView(0).Tag.As(B4XImageView).Bitmap

angel_

Well-Known Member
Licensed User
It works fine but the image is blurry in B4i:
B4X:
    MediaManager.AddLocalMedia(TempFlip, bmp_flip, "image/*")
    MediaManager.SetMedia(Panel1, TempFlip)
 
Upvote 0

angel_

Well-Known Member
Licensed User
The panel is seen with a white background while the image is loading (there are many), is it possible that this panel is seen with a transparent background?, the color of the panel and smm has already been indicated with a white background
 
Upvote 0

angel_

Well-Known Member
Licensed User
The panel is seen with a white background while the image is loading (there are many), is it possible that this panel is seen with a transparent background?, the color of the panel and smm has already been indicated with a white background
B4X:
MediaManager.DefaultLoadingRequest.Extra.Put(MediaManager.REQUEST_BACKGROUND, xui.Color_Transparent)
 
Upvote 0

angel_

Well-Known Member
Licensed User
It isn't related to SMM. Use the latest version of BitmapCreatorEffects and set ScaleDownImages to False: https://www.b4x.com/android/forum/threads/b4x-bitmapcreator-effects.93608/#content
I still get the flipped image blurry, I have this code:

B4X:
    Dim MM As SimpleMediaManager = B4XPages.MainPage.MediaManager
    Dim FlipTemporal As String = "TempFlip.png"
    Dim bmp As B4XBitmap = pnl_img.Snapshot
    Dim bmp_flip As B4XBitmap
    Dim effect As BitmapCreatorEffects
    Dim bmp_scaled As B4XBitmap
    
    effect .Initialize
    effect .ScaleDownImages = False
    bmp_flip = effect .FlipHorizontal(bmp)
    bmp_scaled = bmp_volteado.Resize(bmp_flip.Width * effect .ImageScale, bmp_flip.Height * effect .ImageScale, True)
    
    MM.AddLocalMedia(FlipTemporal, bmp_scaled, "image/*")
    MM.SetMedia(pnl_img, FlipTemporal)
 
Upvote 0

angel_

Well-Known Member
Licensed User
I was creating the example and it seems to me this error:

B4X:
B4i line: 99
sm.CustomView.As(WebView).LoadUrl(Media.Media)
expected expression
 

Attachments

  • Project.zip
    193.6 KB · Views: 54
Upvote 0
Top