Android Question How to capture a snapshot of BCTextEngine

asales

Expert
Licensed User
Longtime User
I use this code to get a snapshot of a scrollview in a panel:
B4X:
Dim x As B4XView = panel1
Dim b As Bitmap = x.Snapshot

Is possible to get snapshot of all BCTextEngine content (even out of the screen)?

I tried with this code, but I'm get only the visible screen:
B4X:
Dim x As B4XView = BBCodeView1.sv

Thanks in advance for any tip.
 

asales

Expert
Licensed User
Longtime User
Thanks. This code works:
B4X:
BBCodeView1.LazyLoading = False
(...)
Dim imagen As B4XBitmap = BBCodeView1.ForegroundImageView.GetBitmap
Dim Out As OutputStream
Out = File.OpenOutput(Starter.rp.GetSafeDirDefaultExternal(""), "pagina1.png", False)
imagen.WriteToStream(Out, 100, "PNG")
Out.Close
but I get a black background in the image.
I'm using the BCTextEngine Example and changed the colordrawable of BBCodeView to white.
snapshot_bccodeview1.jpg
What could be the problem and how I can fix it?
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Are you sure that it is not transparent? Try to change the color behind it.
Yes, it save as transparent background.

Even though I changed the color of the activity, the customlistview and the bbcodeview, it still save with a transparent background.

I get a black background in JPG and a transparent background in PNG in the snapshot and I want to get a white background.

bctext2.png pagina1.jpg pagina1.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Even though I changed the color of the activity, the customlistview and the bbcodeview, it still save with a transparent background.
This is expected. The text is drawn without any background on ForegroundImageView.
Create a B4XCanvas. Draw the background and then draw ForegroundImageView.GetBitmap.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Create a B4XCanvas. Draw the background and then draw ForegroundImageView.GetBitmap.
Can you help with the code. I don't know how to do this.
The code below raises an error: java.lang.ClassCastException: android.graphics.Bitmap cannot be cast to android.view.View
B4X:
Dim c As B4XCanvas
Dim x As B4XView = BBCodeView1.ForegroundImageView.GetBitmap
c.Initialize(x)
Dim b As B4XBitmap = c.CreateBitmap
b.WriteToStream(File.OpenOutput(img_dir, img_name, False), 80, "JPEG")
Thanks!
 
Upvote 0

asales

Expert
Licensed User
Longtime User
I don't understand, yet. My code still gets a black background:
B4X:
Dim b As Bitmap = BBCodeView1.ForegroundImageView.Snapshot  'get the size to set the panel

Dim c As B4XCanvas
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, b.width, b.height)
c.Initialize(p)

Dim r As B4XRect
r.Initialize(0, 0, b.Width, b.Height)

c.DrawBitmap(BBCodeView1.ForegroundImageView.GetBitmap, r)

Dim b1 As B4XBitmap = c.CreateBitmap
b1.WriteToStream(File.OpenOutput(img_dir, img_nome, False), 80, "JPEG")
 
Upvote 0

asales

Expert
Licensed User
Longtime User
This is a mistake. You should use GetBitmap.
Almost there.

I use this code to get the full size of BBCodeView1 (with the text outside of the screen) and resize the panel to use in the canvas.
B4X:
Dim b As Bitmap = BBCodeView1.ForegroundImageView.Snapshot 'get the size to set the panel
(...)
p.SetLayoutAnimated(0, 0, 0, b.width, b.height)
How I can get the full size of the BBCodeView content?
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Another issue:
As I can get a white blackground now, I saw that the images and components (button, clv) are not capture in the snapshot.

What could be the problem?
teste1.jpg
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I use this code to get the full size of BBCodeView1 (with the text outside of the screen) and resize the panel to use in the canvas.
No. No.
B4X:
Dim v As B4XView = BBCodeView1.ForegroundImageView
p.SetLayoutAnimated(0, 0, 0, v.width, v.height)


As I can get a white blackground now, I saw that the images and components (button, clv) are not capture in the snapshot.

What could be the problem?
That's true. Only the text is drawn on ForegroundImageView. The images and other views are added as views to the internal ScrollView. With some work, you can get the views positions and draw them on the canvas.
 
Upvote 0
Top