android - Create a bitmap of text with shadow -
android - Create a bitmap of text with shadow -
i want create bitmap of text shadow, can't result. problem is, when straight draw text, looks good, when draw text bitmap, , draw bitmap, looks ugly.
code:
public class myview extends view { private paint paint; private bitmap bitmap; public myview(context context, attributeset attrs) { super(context, attrs); init(); } public void init(){ paint = new paint(); paint.setcolor(color.black); paint.settextsize(50); paint.setantialias(true); paint.settypeface(typeface.create("helvetica", typeface.normal)); paint.setshadowlayer(30, 0, 0, color.black); bitmap = bitmap.createbitmap(500, 300, bitmap.config.argb_8888); canvas canvas2 = new canvas(bitmap); canvas2.drawtext("dec use", 100, 100, paint); } @override protected void ondraw(canvas canvas){ super.ondraw(canvas); final boolean usebitmap = true; if(usebitmap){ canvas.drawbitmap(bitmap, 0, 0, null); } else{ canvas.drawtext("dec use", 100, 100, paint); } } }
when usebitmap
set false
, result looks
when usebitmap
set true
, result looks this
am missing something?
the loss of quality seems related bitmap. can improve result using grey shadow , using bigger bitmaps (even if means resing after).
bitmap = bitmap.createbitmap(2000, 2000, bitmap.config.argb_8888); canvas canvas2 = new canvas(bitmap); canvas2.drawtext("dec use", 200, 200, paint); paint.setshadowlayer(20, 0, 0, color.gray); canvas2.drawtext("dec use", 200, 200, paint);
related answer
android text bitmap draw shadow
Comments
Post a Comment