Android adds watermark text to a picture

Source: Internet
Author: User

Import Android.os.bundle;import Android.widget.imageview;import Android.app.activity;import Android.graphics.bitmap;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.graphics.drawable.bitmapdrawable;import android.graphics.drawable.Drawable ;p ublic class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); ImageView IV = (ImageView) Findviewbyid ( R.id.imageview);//For simple period, use Android native small robot as target picture drawable drawable = Getresources (). Getdrawable (R.drawable.ic_ Launcher)///drawable-bitmap:drawable convert to Bitmap. bitmapdrawable BD = (bitmapdrawable) drawable; Bitmap bmp = Bd.getbitmap ();//Add watermark to Bitmap Bitmap Bitmap = Createwatermark (BMP, "@ Zhang Phil"); Iv.setimagebitmap (Bitmap) ;} Add watermark text to image target//Bitmap target: Watermark-added picture//String mark: Watermark article private Bitmap Createwatermark (Bitmap target, String Mark) {int w = target.getwidth (); int h= Target.getheight (); Bitmap bmp = Bitmap.createbitmap (W, H, Bitmap.Config.ARGB_8888); Canvas canvas = new canvas (BMP); Paint p = new paint ();//Watermark Color P.setcolor (color.red);//Watermark Font size p.settextsize (Ten);p. Setantialias (TRUE);// Anti-aliasing Canvas.drawbitmap (target, 0, 0, p);//Add Watermark Canvas.drawtext (Mark, 0, H/2, p) in the middle position on the left, Canvas.save (canvas.all_save_ FLAG); Canvas.restore (); return bmp;}}

Android adds watermark text to a picture

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.