Android Question Snapshot of panel

Almog

Active Member
Licensed User
Hello,

I used erel solution for snapshot an item (for example - panel) - (https://www.b4x.com/android/forum/threads/save-only-the-image-inside-the-panel.92333/#post-583937)

B4X:
Sub Button1_Click
    
    Dim bmp As B4XBitmap = Crop_Image(Panel1, Panel1.left, Panel1.top, Panel1.width, Panel1.height )
    Dim out As OutputStream
    out = File.OpenOutput(File.DirInternal, "1.png", False)
    bmp.WriteToStream(out, 100, "PNG")
    out.Close
    
End Sub

Sub Crop_Image(V As B4XView, left As Int, top As Int, width As Int, height As Int) As Bitmap
    
    Return V.Snapshot.Crop(left, top, width, height)
    
End Sub
But the image saved is null - white picture only.

Does anyone know what is the problem and how to fix it?

Thanks in advance
 

ilan

Expert
Licensed User
Hello,

I used erel solution for snapshot an item (for example - panel) - (https://www.b4x.com/android/forum/threads/save-only-the-image-inside-the-panel.92333/#post-583937)

B4X:
Sub Button1_Click
   
    Dim bmp As B4XBitmap = Crop_Image(Panel1, Panel1.left, Panel1.top, Panel1.width, Panel1.height )
    Dim out As OutputStream
    out = File.OpenOutput(File.DirInternal, "1.png", False)
    bmp.WriteToStream(out, 100, "PNG")
    out.Close
   
End Sub

Sub Crop_Image(V As B4XView, left As Int, top As Int, width As Int, height As Int) As Bitmap
   
    Return V.Snapshot.Crop(left, top, width, height)
   
End Sub
But the image saved is null - white picture only.

Does anyone know what is the problem and how to fix it?

Thanks in advance
Because V is Panel1 you should set 0 for left and 0 for top!
B4X:
Dim bmp As B4XBitmap = Crop_Image(Panel1, 0, 0, Panel1.width, Panel1.height )
 

ilan

Expert
Licensed User
Thank you.
btw if you want to get a screenshot of the whole panel you dont need to crop it. just use:

B4X:
Dim Out As OutputStream
Out = File.OpenOutput(File.DirInternal, "Test.png", False)
p.Snapshot.WriteToStream(Out, 100, "PNG")
Out.Close
you can use directly the p.snapshot feature as the b4xbitmap and save it to a file.
 

Almog

Active Member
Licensed User
btw if you want to get a screenshot of the whole panel you dont need to crop it. just use:

B4X:
Dim Out As OutputStream
Out = File.OpenOutput(File.DirInternal, "Test.png", False)
p.Snapshot.WriteToStream(Out, 100, "PNG")
Out.Close
you can use directly the p.snapshot feature as the b4xbitmap and save it to a file.
Hi Ilan,

Thanks for the help, but these 2 solutions are not working either, same result...

Thanks in advance.
 

ilan

Expert
Licensed User
Hi Ilan,

Thanks for the help, but these 2 solutions are not working either, same result...

Thanks in advance.
You should post a simple project example with your code so we can see what is not working. We cannot help you without seeing what yoi are doing in your code.
 
Top