Android imageutils image processing Tool class

Source: Internet
Author: User

/** * 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.