Android Question [SOLVED]B4xtable snapshot

harinder

Active Member
Licensed User
Longtime User
After setting data in B4xtable, I take snapshot as follows:
B4X:
Sub button1_click
    Dim bmp As B4XBitmap=B4XTable1.mBase.Snapshot
    Dim out As OutputStream
    out = File.OpenOutput(s.GetSafeDirDefaultExternal("yo"),  DateTime.Now&".png", False)
    bmp.WriteToStream(out, 100, "PNG")
    out.Close
    ToastMessageShow("check snapshot.example/.jpg",False)
End Sub
But snapshot taken is of full phone screen. How can I take snapshot of only complete B4xtable, as I have to further use it to make pdf files as per Erel's Printing library? What am doing wrong here? Thanks..
Note: s is runtimepermission
 

LucaMs

Expert
Licensed User
Longtime User
Your code is correct. I tried it with Erel's B4XTableExample and this is the result:

1607661577252.png
 
Upvote 0

harinder

Active Member
Licensed User
Longtime User
Thank you LucaMs.
Erel, actually the table is large. It has approx 600 rows and 15 columns. How can I possibly work around that ? Thnx
 
Upvote 0

harinder

Active Member
Licensed User
Longtime User
Erel..got it..mbase is nothing but a panel and b4xtable is made of this panel. So, one can keep increasing the size of the b4xtable in the designer as per requirement and even not make it visible, but the snapshot dimensions will be as per mbase size..
 
Upvote 0

harinder

Active Member
Licensed User
Longtime User
But how do I change mbase height programmatically as per the loaded sql data in the b4xtable? Width is known as per the number of columns..
 
Upvote 0

harinder

Active Member
Licensed User
Longtime User
Solved..

Add a process global variable(say w) and assign it value w=rs.rowcount while adding sql data to b4xtable

Add following line after adding data before taking snapshot:
B4XTable1.mBase.Height=w*B4XTable1.RowHeight+100dip
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
actually the table is large. It has approx 600 rows and 15 columns.
I am glad you were able to solve your problem, but I am still puzzled by the results:
1. If you have a table consisting of 600 rows and 15 columns, when you change the B4XTable height based on the number of records, you are going to get one screenshot of somewhere between 60 and 120 MB in size, possibly more. That is huge.
2. When you take a snapshot of the data in B4XTable, you are not going to be able to see the data to the right. It only takes a snapshot of the visible data only. If you have 15 columns, you may only see 4 or 5 of them in the image.
3. It seems to me the proper approach is to export the B4XTable to a CSV file, open it with a viewer or Excel on the PC, maybe convert to a pdf and run with it.
4. Could you please explain to me how you were able to get it done.
Thank you
 
Upvote 0

harinder

Active Member
Licensed User
Longtime User
The height of snapshot is adjusted depending on the number of actual rows, as shared in my last post.
As far as width is concerned, I have increased the same in the designer as per my requirement of 15 columns, as the number of columns remain fixed. So I have set it to 540%x.
I am taking JPEG snapshot with quality set to 5, wHich is giving me fairly clear snapshots of my data. Size is about 8mb for 600 rows, 15 columns(which is an extreme case, as in usual practical scenario, snapshot would be of lesser data as per filter criteria and requirement).
As I have stated earlier, I am using this snapshot to make pdf pages as per Erel's library. Once the pdf pages are obtained, this snapshot will be discarded. Haven't got there yet, though:p
 
Upvote 0

harinder

Active Member
Licensed User
Longtime User
I could create a pdf page by this method with close to 330 rows and 15 columns(this is a max-out, just for testing !!) on a single page by adjusting b4xtable rowheight to 25dip. Rows on pdf are easily readable, courtesy different shading of alternate rows. Pdf size 2.75mb..
 
Upvote 0
Top