Watermarks images in Android

Source: Internet
Author: User

Watermarks images in Android
Watermark code

Public Bitmap addWaterMark (Bitmap src, String water, Context context) {Bitmap tarBitmap = src. copy (Config. ARGB_8888, true); int w = tarBitmap. getWidth (); int h = tarBitmap. getHeight (); Canvas canvas = new Canvas (tarBitmap); // enable anti-aliasing and use the device's text field to Paint textPaint = new Paint (Paint. ANTI_ALIAS_FLAG | Paint. DEV_KERN_TEXT_FLAG); // set textPaint for the font. setTextSize (35366f); // font size textPaint. setTypeface (Typeface. DEFAULT_BOLD); textPaint. setColor (Color. BLACK); textPaint. setShadowLayer (3f, 1, 1, context. getResources (). getColor (android. r. color. background_dark); // position of the watermark added to the image. Here, the canvas is set at the lower part of the image. drawText (water, (float) (w * 0.05), (float) (h * 0.9), textPaint); canvas. save (Canvas. ALL_SAVE_FLAG); canvas. restore (); return tarBitmap ;}
Watermark code line feed

In fact, canvas. drawText () cannot be automatically wrapped.
Adding/r/n to the string parameter is invalid.
The Code is as follows:

Public Bitmap addWaterMark1 (Bitmap src, String water, Context context) {Bitmap tarBitmap = src. copy (Config. ARGB_8888, true); int w = tarBitmap. getWidth (); int h = tarBitmap. getHeight (); Canvas canvas = new Canvas (tarBitmap); // enable anti-aliasing and use the device's text field TextPaint textPaint = new TextPaint (Paint. ANTI_ALIAS_FLAG | Paint. DEV_KERN_TEXT_FLAG); // set textPaint for the font. setTextSize (35366f); // font size textPaint. setTypeface (Typeface. DEFAULT_BOLD); textPaint. setColor (Color. BLACK); textPaint. setShadowLayer (3f, 1, 1, context. getResources (). getColor (android. r. color. background_dark); StaticLayout layout = new StaticLayout (water, textPaint, 500, Alignment. ALIGN_NORMAL, 1.0F, 0.0F, true); canvas. save (); canvas. translate (float) (w * 0.05), (float) (h * 0.9); // draw layout from 20 to 20. draw (canvas); canvas. save (Canvas. ALL_SAVE_FLAG); return tarBitmap ;}

The parameter 500 in StaticLayout is used to set the length before the line feed starts.

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.