android - Drawing HTML with Paint -
i'm trying draw text on google map fragment generating bitmap , placing marker. text needs stylized via html. wondering if possible.
public static bitmap createpuretexticon(string text){ paint textpaint = new paint(); //textpaint.settypeface(typefaceutil.get(m)) textpaint.settextsize(map_display_text_size); textpaint.setantialias(true); textpaint.settextalign(paint.align.left); float baseline = -textpaint.ascent(); // ascent() negative int width = (int) (textpaint.measuretext(text) + 0.5f); // round int height = (int) (baseline + textpaint.descent() + 0.5f); charsequence m = viewutil.notrailingwhitelines(html.fromhtml(text)); //height * 2 bitmap image = bitmap.createbitmap(width, height, bitmap.config.argb_8888); canvas canvas = new canvas(image); canvas.drawtext(m.tostring(), 0, baseline, textpaint); //canvas.translate(0, height*4); return image; } example html
i need render <br />
<p style=\"text-align: center;\">looking<br />at earth </p>
try canvas.drawtext(html.fromhtml(text), 0, baseline, textpaint); fromhtml converts string of html spannable can drawn.
Comments
Post a Comment