problem in writing text to image

mkvidyashankar

Active Member
Licensed User
Longtime User
I am trying to write text on canvas based on input from a edittext view
B4X:
Sub edittxtOK_Click
     inserttext(txtinsert)   
    image_edit.Invalidate
    bmap.Initialize3(image_edit.Bitmap)
End Sub
Sub inserttext(txt As String) As Bitmap
    Dim bmpedited As Bitmap
    bmpedited.InitializeMutable(bmap.width, bmap.height)
    Dim c As Canvas
    c.Initialize2(bmpedited)
    Dim paint As ABPaint
    paint.Initialize
    paint.setTypeface(myfont1)
   paint.SetColor(Colors.Yellow)
   '
   'Dim rect1 As Rect
   Dim width,height As Float
    width = c.MeasureStringWidth(txt,myfont1,10)
    height =c.MeasureStringHeight(txt,myfont1,10)
   ExDraw.drawText2(c,txt,0,width,0,0, paint)
    Return bmpedited
   edittxtOK.Visible=False
End Sub


getting outofboundexception error in Exdraw.DrawText2

how to solve this :sign0085:
 

klaus

Expert
Licensed User
Longtime User
Your problem is in this line:
B4X:
ExDraw.drawText2(c,txt,0,width,0,0, paint)
drawText2(mCanvas As CanvasWrapper, text As String, start As Int, end As Int, x As Float, y As Float, paint As ABPaint)
Where:
start The index of the first character in text to draw
end (end - 1) is the index of the last character in text to draw

You could use:
B4X:
ExDraw.drawText(c,txt,0,0, paint)
Best regards.
 
Upvote 0

mkvidyashankar

Active Member
Licensed User
Longtime User
Log

LogCat connected to: B4A-Bridge: LGE LG-P500-354043045942903
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
main_inserttext (B4A line: 1818)
ExDraw.drawText2(c,txt,0,width,0,0, paint)
java.lang.IndexOutOfBoundsException
at android.graphics.Canvas.drawText(Canvas.java:1278)
at com.AB.ABExtDrawing.ABExtDrawing.drawText2(ABExtDrawing.java:306)
at com.camera.main._inserttext(main.java:3731)
at com.camera.main._edittxtok_click(main.java:2719)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:101)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:97)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
java.lang.IndexOutOfBoundsException
 
Upvote 0
Top