android - Draw text on canvas and make it visible on screen -
this code supposed convert text image
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); paint paint = new paint(); paint.setstyle(paint.style.fill); paint.setcolor(color.red); paint.settextsize(16); paint.setantialias(true); paint.settypeface(typeface.monospace); bitmap bm = bitmap.createbitmap(16, 16, bitmap.config.alpha_8); float x = bm.getwidth(); float y = bm.getheight(); canvas c = new canvas(bm); c.drawtext("test", x, y, paint); }
is code ok? if yes, how can make new bitmap visible on screen? tried code produced error
setcontentview(c); //<- error!
i confused element canvas
there not such element in xml can use in code.
setcontentview(view)
takes view
, canvas not view
.
i not sure want create canvas
on own. there ways canvas
passed android framework though. 1 way can creating custom view
. this, need create new class extends view
.
when overriding view
class, have ability override ondraw(canvas)
method. want attempting in oncreate()
method in code posted.
this link gives overview of required create own custom view.
Comments
Post a Comment