Android Question Skewing B4XImageView?

wimpie3

Well-Known Member
Licensed User
Longtime User
How can I get this Skew effect on a B4XImageView?

skewY-example.jpg
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Better to write in the question, which platforms are targeted. It took me sometime to find that thread.

Not perfect but it can help you get started with implementing it based on BitmapCreator:

1635752751780.png


B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private B4XImageView1 As B4XImageView
    Private B4XImageView2 As B4XImageView
    Private bce As BitmapCreatorEffects
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XImageView1.mBackgroundColor = xui.Color_Transparent
    B4XImageView2.mBackgroundColor = xui.Color_Transparent
    Dim bmp As B4XBitmap = xui.LoadBitmap(File.DirAssets, "10039.jpg")
    B4XImageView1.Bitmap = bmp
    bce.Initialize
    B4XImageView2.Bitmap = Skew(bmp, 20)
End Sub

Private Sub Skew(bmp As B4XBitmap, Degrees As Float) As B4XBitmap
    Dim orig As BitmapCreator = bce.CreateBC(bmp)
    Dim modif As BitmapCreator = bce.CreateEmptyBC(bmp)
    Dim shift As Float = SinD(Degrees)
    Dim scale As Float = (orig.mHeight - orig.mWidth * shift) / orig.mHeight
    Dim pm As PremultipliedColor
    For x = 0 To orig.mWidth - 1
        For y = 0 To orig.mHeight - 1
            Dim yt As Float = (orig.mWidth - x) * shift + y * scale
            orig.GetPremultipliedColor(x, y, pm)
            modif.SetPremultipliedColor(x, yt, pm)
        Next
    Next
    Return modif.Bitmap
End Sub
 
Upvote 1

wimpie3

Well-Known Member
Licensed User
Longtime User
Better to write in the question, which platforms are targeted. It took me sometime to find that thread.

Sorry, I thought that was clear in the title since I used 'B4XImageView'. Thank you very much for the example!
 
Upvote 0
Top