Android Question [SOLVED]Capture image from Camera2 with overlaid compass

josejad

Expert
Licensed User
Longtime User
Hi everybody:

I use Camera2 to make pictures in my app. In some of these pictures, I need to know the compass orientation, so I've overlaid a compass over the camera preview, and I need to save the image with the overlaid compass.
I've tried to define
Code: Copy
pnlCamera as B4XView
..
cam.Initialize(pnlCamera)
...
Dim bmp As B4XBitmap = pnlCamera.Snapshot

But I get a black screen with the compass and the views in the pnlCamera, but not the image itself.
The resulting image is too small too (about 19kb).

I've been reading about BitmapCreator, but not sure if it's what I need. Maybe with this I could save the image as always, the pnlCamera.Snapshot and overlay them?

Thanks.
 
You can use BitmapCreator or Canvas / B4XCanvas.

With BitmapCreator it will be something like:
Code: Copy
Dim bmp As B4XBitmap = cam.DataToBitmap(Data)
Dim bmp2 As B4XBitmap = LoadBitmap(File.DirAssets, "android-chrome-192x192.png")
Dim bc As BitmapCreator
bc.Initialize(bmp.Width, bmp.Height)
bc.CopyPixelsFromBitmap(bmp)
Dim r As B4XRect
r.Initialize(20dip, 20dip, 0, 0)
r.Width = bmp2.Width
r.Height = bmp2.Height
bc.DrawBitmap(bmp2, r, False)
Dim mergedbmp As B4XBitmap = bc.Bitmap
 
Upvote 0
Awesome¡¡ It works¡¡
Is there a way of setting the color panel to transparent. I've set to transparent, but I get it black

7045.jpg


Thanks
 
Last edited:
Upvote 0
I've been reading about DrawBitmapCreator, searching about transparency...
In the thumbnail it seems to work, but in the image I don't get the compass with transparent background.
I've changed the line
Code: Copy
bc.DrawBitmap(bmp2, r, False)
with
Code: Copy
bc.DrawBitmapCreator(bc,r,50,50,True)
but no success...

Code: Copy
        Dim bmp As B4XBitmap = cam.DataToBitmap(Data)
        Dim bmp2 As B4XBitmap = pnlCompass.Snapshot
        Dim bc As BitmapCreator
        bc.Initialize(bmp.Width, bmp.Height)
        bc.CopyPixelsFromBitmap(bmp)
        Dim r As B4XRect
        r.Initialize(20dip, 20dip, 0, 0)
        r.Width = bmp2.Width
        r.Height = bmp2.Height
        bc.DrawBitmapCreator(bc,r,50,50,True)
        Dim mergedbmp As B4XBitmap = bc.Bitmap
 
Upvote 0
Upvote 0
The code I posted keeps the transparent parts. The problem is in the bitmap that you are drawing

You're right. Just adding:
Code: Copy
pnlCompass.Color = Colors.Transparent
I get it right¡¡
I thought just setting the transparency level to 0 in designer was enough, but it's not

Thanks a lot

7045 (1).png
 
Last edited:
Upvote 0
Back
Top