Android Question Flip b4xCanvas?

Pflichtfeld

Active Member
Licensed User
thank you Luca. I have dealt with BitmapCreator, but cannot apply it to my problem. The FlipcompressedBitmap-Method aplies to CompressedBC. I cannot find a way with bitmapCreator, to flip a canvas or bitmap.
I 've been surfing around in this forum to find an easy way to flip a canvas or a bitmap, but was not successful. (most of the examples simply use canvas, but I want to do it crossplattform)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Have you tried this:

B4X:
'flips an image
'Orientation 0 = horizontally  1 = vertically  2 = both
Public Sub Flip(Image As B4XBitmap, Orientation As Int) As B4XBitmap
    Private xf, yf, x, y As Int
    Private col0 As ARGBColor
    Private bmcImage, bmcResult As BitmapCreator
    
    bmcImage.Initialize(Image.Width, Image.Height)
    bmcImage.CopyPixelsFromBitmap(Image)
    bmcResult.Initialize(Image.Width, Image.Height)
    Select Orientation
        Case 0
            For y = 0 To Image.Height - 1
                For x = 0 To Image.Width - 1
                    bmcImage.GetARGB(x, y, col0)
                    bmcResult.SetARGB(x, y, col0)
                Next
            Next
        Case 1
            For y = 0 To Image.Height - 1
                For x = 0 To Image.Width - 1
                    xf = Image.Width - 1 - x
                    bmcImage.GetARGB(x, y, col0)
                    bmcResult.SetARGB(xf, y, col0)
                Next
            Next
        Case 2
            For y = 0 To Image.Height - 1
                For x = 0 To Image.Width - 1
                    yf = Image.Height - 1 - y
                    bmcImage.GetARGB(x, y, col0)
                    bmcResult.SetARGB(x, yf, col0)
                Next
            Next
        Case 3
            For y = 0 To Image.Height - 1
                For x = 0 To Image.Width - 1
                    xf = Image.Width - 1 - x
                    yf = Image.Height - 1 - y
                    bmcImage.GetARGB(x, y, col0)
                    bmcResult.SetARGB(xf, yf, col0)
                Next
            Next
    End Select
    Return bmcResult.Bitmap
End Sub

Extracted from the B4X Graphics booklet source code, BitmapCreatorDemo1 project.
 
Upvote 0

Pflichtfeld

Active Member
Licensed User
Thank you Klaus !!
Seems that I have lots of difficulties:
1. in the B4xGraphicsV1_7.pdf, I have here (Last update: 2020.02.06), search for 'Flip(Image' or 'Sub Flip' nothing is found, same is with your link
2. page 8 (and 11) in my B4xGraphicsV1_7.pdf tells me, there would be a DrawBitmapFlipped-Method. The intellisense does not know this method:
bitmapFlipped.png

3. In my downloaded examples, BitmapCreator1-3 has just b4j-files. No b4a examples.
(4. the code, you posted, copies pixel by pixel. Isn't this very slow? Isn't there a ready, fast routine for this?)

(The more I deal with b4a, the more I appreciate it. But it also confuses me with it's wide spread and partially contradictory informations. f.i. your nice latest fitForCenterImage-example, that I just found by chance - older version I found earlier...)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
thank you Luca. I have dealt with BitmapCreator, but cannot apply it to my problem. The FlipcompressedBitmap-Method aplies to CompressedBC. I cannot find a way with bitmapCreator, to flip a canvas or bitmap.
I 've been surfing around in this forum to find an easy way to flip a canvas or a bitmap, but was not successful. (most of the examples simply use canvas, but I want to do it crossplattform)
(The more I deal with b4a, the more I appreciate it. But it also confuses me with it's wide spread and partially contradictory informations. f.i. your nice latest fitForCenterImage-example, that I just found by chance - older version I found earlier...)
The real problem is that you are not reading the posts.
Go to BitmapCreaterEffects. Download the library and use effects.FlipVertical or FlipHorizontal to flip the images.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
2. page 8 (and 11) in my B4xGraphicsV1_7.pdf tells me, there would be a DrawBitmapFlipped-Method.
The table on page 11 shows the available methods with the different canvases.
The DrawBitmapFlipped method you are speaking of is in the B4A column, therefore only available with a B4A Canvas.

In my downloaded examples, BitmapCreator1-3 has just b4j-files. No b4a examples.
The code in the routines runs on all three platforms.
This is clearly written on top of the BitmapCreatorDemo1 page.
Only the B4J program is shown, all the routines are valid for B4A and B4i.
 
Last edited:
Upvote 0

Pflichtfeld

Active Member
Licensed User
The real problem is that you are not reading the posts.
Go to BitmapCreaterEffects. Download the library and use effects.FlipVertical or FlipHorizontal to flip the images.
My wife keeps on telling me, that I am not listening correctly so you must be wrong ;)
I actually read the BitmapCreatorEffects, studied your example. But in the attached example you have put the BitmapCreatorEffects in a class. In this class no flip-method exists. Sorry, that I did not test the library first, I did not expect it would enclude further methods.
The amount of knowledge is so huge (and not allways condensed in one point), that I have to beg your pardon for my slow learning.
I am dependend of your patience and I thank you for that!
(forgot to say, that these flip-methods are really great!)
 
Last edited:
Upvote 0

Pflichtfeld

Active Member
Licensed User
The DrawBitmapFlipped method you are speaking of is in the B4A column, therefore only available with a B4A Canvas.
The code in the routines runs on all three platforms.
Only the B4J program is shown, all the routines are valid for B4A and B4i.
Sorry, I did not understand, that the B4a-Column might not apply, if I use a b4x-object.
B4J: I did not jet download b4j. But if I want to study b4j-projects, I have to do so? Is it correct, that I could replace my coding in VB.Net with b4j and I could develope desktop-apps with B4J as well?
(I would understand, if you told me that this is wrong, so that I don't bother you with additional questions about b4j in the future...)
 
Upvote 0
Top