Android Question How to Generate Text Image with BCTextEngine

xulihang

Well-Known Member
Licensed User
Longtime User
Hi,

I only need to get the text image using BCTextEngine and do not need to display it in BBCodeView. Is there a way to do this?
 

xulihang

Well-Known Member
Licensed User
Longtime User
B4X:
    For Each n As B4XView In BBCodeView1.mBase.GetAllViewsRecursive
        'Log(n)
        If n Is ImageView Then
            Log(n)
            Dim iv As ImageView = n
            If iv.GetImage.IsInitialized Then
                ImageView1.SetImage(iv.GetImage)
            End If
        End If
    Next

I try to get the text image from the image view (B4J here). The image contains empty pixels and the text is cut a bit.

test.png
 
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
EDIT: it seems that only the ImageViews from the ScrollPane's innernode (slightly more than the visible part) are available.
Some ImageViews cut off a piece of the text:
1760156570227.png
1760156654943.png



1760154941428.png

I have added some code (to the BCTextExample from Erel) to collect the ImageViews from the BBCodeView1 using your code from above:
B4X:
    Sleep(2000)
    For Each n As B4XView In BBCodeView1.mBase.GetAllViewsRecursive
        'Log(n)
        If n Is ImageView Then
            Log(n)
            Dim iv As ImageView = n
            If iv.GetImage.IsInitialized Then
                Dim pn As Pane = set_clv1item(iv)
                clv1.Add(pn,"")
            End If
        End If
    Next
End Sub
Private Sub set_clv1item(imgview As ImageView) As Pane
    Dim pn As Pane
    pn.Initialize("")
    pn.LoadLayout("clv1item_layout")
    pn.SetLayoutAnimated(0, 0, 0, 560,100)
    iv1.SetImage(imgview.GetImage)
    Return pn
End Sub
The modified source code is in the attachment.
 

Attachments

  • BCTextExample.zip
    18.1 KB · Views: 5
Last edited:
Upvote 0

xulihang

Well-Known Member
Licensed User
Longtime User
I set lazyloading to false and then I can get the image from the ForegroundImageView.

B4X:
BBCodeView1.TextEngine = engine
BBCodeView1.LazyLoading = False
BBCodeView1.Text = "This is a sentence. [b][u]Bold italic.[/u][/b]"
ImageView1.SetImage(BBCodeView1.ForegroundImageView.GetBitmap)
 
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
Yes this works... but the button and the logo's (from the example from Erel) do not appear on the ForegroundImageView bitmap.
Since you are only interested in the text ImageView then that's OK.
It would have been nice to have ALL the ImageViews with the right size available in for instance a Custom ListView as i showed above.
The calculation of the height of the ImageViews is also slightly off and should be fixed too.
In This thread the code from the canvas method MeasureText is inaccurate. I added 2dip to the rectangle width and height.
 
Upvote 0
Top