hi, its more a b4x question then a b4j question. i just post it here because the code i write is in b4j because its much simpler but i need it for b4i.
anyway, i want to return a bitmap from 2 bitmaps drawn one of each other. what would be the best way to do it? (as much b4x as possible)
i do it with b4xcanvas, is it ok? is there a better way? this is my code right now but i dont like it a lot although it works fine. any suggestions are welcome.
when i initialize the b4xcanvas i must enter a targetview so i create a panel but never add it to anywhere, is this ok?
result:
EDIT: Code has been updated to Erels suggestion.
anyway, i want to return a bitmap from 2 bitmaps drawn one of each other. what would be the best way to do it? (as much b4x as possible)
i do it with b4xcanvas, is it ok? is there a better way? this is my code right now but i dont like it a lot although it works fine. any suggestions are welcome.
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Type vec2(left As Float, top As Float, width As Float, height As Float)
Private fx As JFX
Private MainForm As Form
Dim xui As XUI
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
Dim bmp1, bmp2 As B4XBitmap
bmp1 = xui.LoadBitmap(File.DirAssets,"smiling-kid-boy-cartoon-character-vector-15054701.jpg")
bmp2 = xui.LoadBitmap(File.DirAssets,"22-223255_cartoon-trophy-clipart-trophy-clipart.png")
Dim imgv As ImageView
imgv.Initialize("")
imgv.PreserveRatio = True
MainForm.RootPane.AddNode(imgv,50dip,50dip,150dip,200dip)
Dim v As vec2
v.Initialize
v.left = bmp1.Width*0.7
v.top = bmp1.Height*0.7
v.width = bmp1.Width*0.3
v.height = bmp1.Height*0.3
imgv.SetImage(combine2bitmaps(bmp1,bmp2,createrect(v)))
End Sub
Sub createrect(vec As vec2) As B4XRect
Dim rect As B4XRect
rect.Initialize(vec.left,vec.top,vec.left+vec.width,vec.top+vec.height)
Return rect
End Sub
Sub combine2bitmaps(firstBmp As B4XBitmap, secondBmp As B4XBitmap, SecondImageRect As B4XRect) As B4XBitmap
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0,0,0,firstBmp.Width,firstBmp.Height)
Dim c As B4XCanvas
c.Initialize(p)
c.DrawBitmap(firstBmp,c.TargetRect)
c.DrawBitmap(secondBmp, SecondImageRect)
Dim res As B4XBitmap = c.CreateBitmap
c.Release
Return res
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
result:
EDIT: Code has been updated to Erels suggestion.
Attachments
Last edited: