Initialize the canvas to a View. This view doesn't need to be in the layout. Only need to initialize it and assigned dimensions
Draw on it and then get the bitmap
Something similar to (untested, there may be small typos but that's the idea)
Dim cvs As B4XCanvas
Dim myView as B4XView
myView.initialize("")
myView.width = 400 '<-- now I'm not sure if it has to be scaled with device's scale nonNormalizedValues
myView.Height = 400
cvs.Initialize(myView)
' draw here
Dim myBitmap as B4XBitmap = cvs.CreateBitmap '<-- Here you get your bitmap
cvs.Release