B4J Question Save combined Canvas and ImageView

ElliotHC

Active Member
Licensed User
I am capturing an image with a webcam and using a canvas to highlight parts of the image, I am doing this by placing the Canvas in front of it. It works very well.

Currently, when an event occurs, I am saving the image in the ImageView. However, I only have the image and not the information drawn over it with the Canvas.

Is there a way to save both together, perhaps print the screen just in the area of those two overlaid items?
 

DonManfred

Expert
Licensed User
Longtime User
1. Copy the image from the Imageview to the Canvas.
2. Draw on Canvas
3. Save the Canvas-Snapshot
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
    Dim p As Pane = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,722,373)
    Root.AddView(p,0,0,722,373)

    p.LoadLayout("LayoutCanvas")
    Dim bmp As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "ORCLogoF1.png",722dip,373dip,True) ' Load the file you use in Imageview
    cvs.DrawImage(bmp, 0, 0, 722dip, 373dip) ' Draw Image on Canvas
    Dim fnt As Font = xui.CreateDefaultFont(20)
    cvs.DrawText("Test bla bla bla",20dip,90dip,fnt,fx.Colors.Blue,"LEFT") ' Add Text to Canvas
    Dim snap As Image = cvs.Snapshot ' Get Canvas Snapshot
    
    Dim out As OutputStream = File.OpenOutput("D:\", "CanvasImageCombined.png", False) ' Write Snapshot to Disc.
    snap.WriteToStream(out)
    out.Close

    p.RemoveNodeFromParent
CanvasImageCombined.png
 
Upvote 0

ElliotHC

Active Member
Licensed User
B4X:
    Dim p As Pane = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,722,373)
    Root.AddView(p,0,0,722,373)

    p.LoadLayout("LayoutCanvas")
    Dim bmp As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "ORCLogoF1.png",722dip,373dip,True) ' Load the file you use in Imageview
    cvs.DrawImage(bmp, 0, 0, 722dip, 373dip) ' Draw Image on Canvas
    Dim fnt As Font = xui.CreateDefaultFont(20)
    cvs.DrawText("Test bla bla bla",20dip,90dip,fnt,fx.Colors.Blue,"LEFT") ' Add Text to Canvas
    Dim snap As Image = cvs.Snapshot ' Get Canvas Snapshot
   
    Dim out As OutputStream = File.OpenOutput("D:\", "CanvasImageCombined.png", False) ' Write Snapshot to Disc.
    snap.WriteToStream(out)
    out.Close

    p.RemoveNodeFromParent
View attachment 109182
Thanks.

I think this is too much code for my project. I've looking through 640 X 480 pixels, then box searching 40 x 40. If I get a match I'm taking an image. This might really slow it down a lot if I get 30 or so matches in a frame. It's doing 4 frames a second currently.
 
Upvote 0
Top