Android Question Combine 4x2 imageviews into 1 Jpeg

imbault

Well-Known Member
Licensed User
Longtime User
Hi,
I need to take 8 photos then combine them into 1 photo;

So I will create 4x2 Imageviews side to side, but how to combine that into 1 one Jpeg file?

Any ideas?

Thanks

Patrick
 

imbault

Well-Known Member
Licensed User
Longtime User
Ok thanks Erel, I will have that mosaic with each Canvas.DrawBitmap, but how to save that mosaic into one single file?

Thanks
Patrick
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Try

B4X:
' out = outputstream
' c = canvas
 Out = File.OpenOutput(File.DirRootExternal & "/Images/", "IMG_20178108230.jpg", False)
    C.Bitmap.WriteToStream(Out, 100, "JPEG")
    Out.Close
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
As DonManfred says, it would be something like this (not tested, syntax errors allowed ;))
B4X:
Dim myBitmap(8) as Bitmap
' ... init them

Dim scaleFactor as Float=1   ' or whatever
Dim W as int = scaleFactor*myBitmap(0).Width   ' We are assuming that all bitmaps have equal dimensions.
Dim H as int = scaleFactor*myBitmap(0).Height

Dim totalW as int = 4*W    ' Total width of 4*2 mosaic
Dim totalH as Int = 2*H     ' Total height ...

Dim b as Bitmap
b.initializeMutable(totalW,totalH)
Dim cv as Canvas
cv.initialize2(b)
for r=0 to 1
  for c=0 to 3
    Dim dstRect as Rect
    dstRect.initialize(c*W, r*H, (c+1)*W, (r+1)*H)     '<-- each bitmap will be in a position in the mosaic. No spacing between bitmaps here
    cv.drawBitmap( myBitmap(4*r+c), Null, dstRect)
  next
next

' Now you have your bitmap in b and also in cv.bitmap. Can be saved to jpeg
Dim o As OutputStream
o=File.OpenOutput( Dir_dest, Filename_dest,False)
cv.Bitmap.WriteToStream(o,100,"JPEG")    'or "PNG"  
o.Close
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Maybe you can put the 8 imageviews in a panel and use the function Snapshot from B4XView to capture and save the image in JPEG.

See my example in attach.
 

Attachments

  • panel8.zip
    29.4 KB · Views: 149
Last edited:
Upvote 0
Top