Android Question [Solved] How to flip bitmap in imageview several times?

asales

Expert
Licensed User
Longtime User
I use this code to flip a bitmap horizontally in a imageview and works properly once:

B4X:
Sub btnFlip_Click
    Dim c As Canvas
    c.Initialize(imgvMain)
    Dim r As Rect
    r.Initialize(0, 0, imgvMain.Width, imgvMain.Height)
    c.DrawBitmapFlipped(LoadBitmap(File.DirAssets, "back1.jpg"), Null, r, False, True)
    bmp1.Initialize3(c.Bitmap)  
    imgvMain.Bitmap = bmp1  
End Sub

I want to click again in the same button and the bitmap returns to original position and click again and bitmap is reversed and so on...

The project is in attached.

Thanks in advance for any tip.
 

Attachments

  • flip_image.zip
    16.8 KB · Views: 190

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bmp1 As Bitmap

    Private btnFlip As Button
    Private imgvMain As ImageView
    Private flipped As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")

    bmp1.Initialize(File.DirAssets, "back1.jpg")   
    imgvMain.Bitmap = bmp1   
    flipped = False
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnFlip_Click
    Dim c As Canvas
   
    c.Initialize(imgvMain)
    If flipped = False Then
            Dim r As Rect
        Dim bmp As Bitmap
            bmp.Initialize3(bmp1)
            r.Initialize(0, 0, imgvMain.Width, imgvMain.Height)
        c.DrawBitmapFlipped(bmp1, Null, r, False, True)
            bmp.Initialize3(c.Bitmap)   
            imgvMain.Bitmap = bmp
            flipped = True
        Else
            Dim r As Rect
        Dim bmp As Bitmap
            bmp.Initialize3(bmp1)
            imgvMain.Bitmap = bmp
            flipped = False
   
        End If
End Sub
 
Upvote 0
Top