Android Question xCustomlistview to image

I want to save a xCustomlistview to a jpg file.
I found how to save the visible part using the following code, but I need to save the entire xCustomlistview including the items that are not visible.

Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "Test.jpg", False)
clv2.AsView.Snapshot.WriteToStream(Out, 100, "JPEG")
Out.Close

Dim i As Intent
i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
"file://" & File.Combine(File.DirRootExternal, "Test.jpg"))
Dim p As Phone
p.SendBroadcastIntent(i)
 
I want to save a xCustomlistview to a jpg file.
I found how to save the visible part using the following code, but I need to save the entire xCustomlistview including the items that are not visible.

B4X:
Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "Test.jpg", False)
clv2.AsView.Snapshot.WriteToStream(Out, 100, "JPEG")
Out.Close

Dim i As Intent
i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
"file://" & File.Combine(File.DirRootExternal, "Test.jpg"))
Dim p As Phone
p.SendBroadcastIntent(i)
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Maybe not the nicest or right solution but maybe worth a try
B4X:
clv2.AsView.Tag = CLV.AsView.Height
Dim realheight As Int = 0
For x = 0 To (clv2.Size - 1)
    Dim h As Panel
    h = clv2.GetPanel(x)
    realheight = realheight + h.Height
Next
clv2.AsView.Height = realheight

Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "Test.jpg", False)
clv2.AsView.Snapshot.WriteToStream(Out, 100, "JPEG")
Out.Close

Dim i As Intent
i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
"file://" & File.Combine(File.DirRootExternal, "Test.jpg"))
Dim p As Phone
p.SendBroadcastIntent(i)

clv2.AsView.Height = clv2.AsView.Tag
This code take in consideration the chance that items can have different heights.
If you know that all items are equal you could even use
B4X:
clv2.Asview.tag = clv2.Asview.height
dim h as Panel = clv2.Getpanel(0)
clv2.Asview.height = h.height * clv2.size
 
Last edited:
Upvote 0
It doesn' t work.
The size in the log is different but the Snapshot is still the visible panels.
Code:
    clv2.Asview.tag = clv2.Asview.height
    Log("clv2.Asview.tag = " & clv2.Asview.tag)
    Dim h As Panel = clv2.Getpanel(0)
    clv2.Asview.height = h.height * clv2.size
    Log("clv2.Asview.height = " & clv2.Asview.height)
    
    Dim Out As OutputStream
    Out = File.OpenOutput(File.DirRootExternal, "Test.png", False)
    clv2.AsView.Snapshot.WriteToStream(Out, 100, "PNG")
    Out.Close

    Dim i As Intent
    i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
    "file://" & File.Combine(File.DirRootExternal, "Test.png"))
    Dim p As Phone
    p.SendBroadcastIntent(i)

Code:
LOG
clv2.Asview.tag = 1824
clv2.Asview.height = 2310
 
Upvote 0
Top