/** * Add text to the picture. Similar watermark text. * @param gcontext * @param gresid * @param gtext * @return */public static Bitmap drawtexttobitmap (Context gcontext, int Gresid, String gtext) {Resources resources = gcontext.getresources (); float scale = Resources.getdisplaymetrics (). Density Bitmap Bitmap = bitmapfactory.decoderesource (resources, GRESID); Android.graphics.Bitmap.Config bitmapconfig = Bitmap.getconfig ();//Set Default bitmap config if Noneif (bitmapconfig = = null) {Bitmapconfig = Android.graphics.bitmap.c Onfig. argb_8888;} Resource bitmaps is imutable,//so we need to convert it to mutable onebitmap = Bitmap.copy (Bitmapconfig, true); Canvas canvas = new canvas (bitmap),//new antialised Paintpaint paint = new Paint (paint.anti_alias_flag);//Text Color-# 3d3d3dpaint.setcolor (Color.rgb (61,61,61));//Text Size in pixelspaint.settextsize ((int) (scale*5));//Text Shadowpaint.setshadowlayer (1f, 0f, 1f, color.white);//Draw text to the Canvas centerrect bounds = new Rect ();p Aint.gettex Tbounds (gtext, 0, Gtext.length (), Bounds)//int x = (Bitmap.getwidth ()-bounds.width ())/2;//int y = (bitmap.getheight () + bounds.height ())/2;//draw text to the Bottomint x = (Bitmap.getwidth ()-bounds.width ())/10*9; int y = (bitmap.getheight () + bounds.height ())/10*9;canv As.drawtext (Gtext, x, y, paint); return bitmap;}
Android imageutils image processing Tool class