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: 2
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
Top