H hdtvirl Active Member Licensed User Longtime User Mar 9, 2012 #1 I am writing an app in which I need to transfer some text to a canvas, the user selects the text from a spinner and can edit it in a edit text box and when completed it is transferred to a canvas and saved with some other graphics as a .png format file which is then emailed off the device. I need to wrap the text on word boundaries into a space for text on the RH side of the image, what I am looking to find out is there anyway of getting the length of a piece of text in pixels so I can intelligently wrap the text over 5 or 6 lines. I am using the advance drawing Library so place the text on the canvas is not a problem. I know that I can fit 4/5 average length words into each line but words like 'Brilliantly Intelligent “ would cause and over a wrapping issue. I can t seem to find a split command to split up a line of text into an array of each word using the space as the splitter. Regards BOB
I am writing an app in which I need to transfer some text to a canvas, the user selects the text from a spinner and can edit it in a edit text box and when completed it is transferred to a canvas and saved with some other graphics as a .png format file which is then emailed off the device. I need to wrap the text on word boundaries into a space for text on the RH side of the image, what I am looking to find out is there anyway of getting the length of a piece of text in pixels so I can intelligently wrap the text over 5 or 6 lines. I am using the advance drawing Library so place the text on the canvas is not a problem. I know that I can fit 4/5 average length words into each line but words like 'Brilliantly Intelligent “ would cause and over a wrapping issue. I can t seem to find a split command to split up a line of text into an array of each word using the space as the splitter. Regards BOB
klaus Expert Licensed User Longtime User Mar 9, 2012 #2 is there anyway of getting the length of a piece of text in pixels Click to expand... Yes, Canvas.MeasureStringWidth(Text As String, Typeface As Typeface, TextSize As Float). I can t seem to find a split command to split up a line of text into an array of each word using the space as the splitter. Click to expand... RegEx.Split(Pattern As String, Text As String) Best regards. Upvote 0
is there anyway of getting the length of a piece of text in pixels Click to expand... Yes, Canvas.MeasureStringWidth(Text As String, Typeface As Typeface, TextSize As Float). I can t seem to find a split command to split up a line of text into an array of each word using the space as the splitter. Click to expand... RegEx.Split(Pattern As String, Text As String) Best regards.
rfresh Well-Known Member Licensed User Longtime User Mar 16, 2012 #4 I'm getting a null pointer error on this: Code: Copy Dim width, height As Float Dim Canvas1 as Canvas Dim t As String t = "Text to write" width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)<<<----- height = Canvas1.MeasureStringHeight(t, Typeface.DEFAULT, 14) Upvote 0
I'm getting a null pointer error on this: Code: Copy Dim width, height As Float Dim Canvas1 as Canvas Dim t As String t = "Text to write" width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)<<<----- height = Canvas1.MeasureStringHeight(t, Typeface.DEFAULT, 14)
klaus Expert Licensed User Longtime User Mar 16, 2012 #5 You need to initialze the Canvas with a target view: Code: Copy Dim width, height As Float Dim Canvas1 As Canvas Dim t As String Canvas1.Initialize(Activity) t = "Text to write" width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)<<<----- height = Canvas1.MeasureStringHeight(t, Typeface.DEFAULT, 14) Best regards. Upvote 0
You need to initialze the Canvas with a target view: Code: Copy Dim width, height As Float Dim Canvas1 As Canvas Dim t As String Canvas1.Initialize(Activity) t = "Text to write" width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)<<<----- height = Canvas1.MeasureStringHeight(t, Typeface.DEFAULT, 14) Best regards.