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
B4X:
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.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use BitmapCreator or Canvas / B4XCanvas.

With BitmapCreator it will be something like:
B4X:
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

josejad

Expert
Licensed User
Longtime User
Awesome¡¡ It works¡¡
Is there a way of setting the color panel to transparent. I've set to transparent, but I get it black



Thanks
 
Last edited:
Upvote 0

josejad

Expert
Licensed User
Longtime User
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
B4X:
bc.DrawBitmap(bmp2, r, False)
with
B4X:
bc.DrawBitmapCreator(bc,r,50,50,True)
but no success...

B4X:
        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

josejad

Expert
Licensed User
Longtime User
Upvote 0

josejad

Expert
Licensed User
Longtime User
The code I posted keeps the transparent parts. The problem is in the bitmap that you are drawing

You're right. Just adding:
B4X:
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

 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…