Android Question How to combine two photos into one photo.

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I have 2 photos/images and I want to create a new one by combining the 2 previous ones. One on top of the other. They are supposed to have transparent parts so they don't overlap.
Let me explain with an example, I have a photo of a house and a photo of the sun and I want to show the combination of both, something like this:




How can this be done?
Thank you.
 

Alexander Stolte

Expert
Licensed User
Longtime User
B4X:
    Dim bmp_1 As B4XBitmap
    Dim bmp_2 As B4XBitmap
    
    Dim cv As B4XCanvas
    
    cv.Initialize(YourView)
    
    Dim rect As B4XRect
    rect.Initialize(0,0,bmp_1.Width,bmp_1.Height)
    
    cv.DrawBitmap(bmp_1,rect)
    
    rect.Initialize(bmp_1.Width,0,bmp_1.Width + bmp_2.Width,bmp_2.Height)
    
    cv.DrawBitmap(bmp_2,rect)
cv.Invalidate

It is easier if you have a list of images:
B4X:
    cv.Initialize(xpnl)
    For i = 0 To lst_images.size -1
    
        Dim bmp_part As B4XBitmap = lst_images.Get(i)
    
        Dim rect As B4XRect
        rect.Initialize(bmp_part.Width*i,0,bmp_part.Width*(i+1),bmp_part.Height)
    
        cv.DrawBitmap(bmp_part,rect)
    
    Next
    
    cv.Invalidate
 
Upvote 1

emexes

Expert
Licensed User
They are supposed to have transparent parts so they don't overlap.

If they have transparent parts (ie an alpha/opacity channel/plane) then probably simpler to just load each image into its own view, and move them about by changing the view's position properties. Better yet, you can probably then also independently rotate the views by an arbitrary and individual angle eg 37 degrees or 60 degrees or whatever.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…