Android to achieve image plus watermark

Source: Internet
Author: User

Add 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 antialiasing and use device text kerning paint textpaint = new paint (Paint. ANTI_alias_flag | Paint. DEV_kern_text_flag); font-related Settings textpaint. Settextsize(35.0F;//font sizeTextpaint. Settypeface(Typeface. DEFAULT_bold); Textpaint. SetColor(Color. BLACK); Textpaint. Setshadowlayer(3F1,1, context. Getresources(). GetColor(Android. R. Color. Background_dark)); The location of the watermark is added to the image, which is set to the lower middle3/4Place Canvas. DrawText(Water, (float) (w*0.05), (float) (h*0.9), Textpaint); Canvas. Save(Canvas. All_save_flag); Canvas. Restore(); Return Tarbitmap; }
Watermark Code Line Wrapping

In fact, the Canvas.drawtext () is not possible to implement automatic line wrapping.
Adding/r/n to the string parameter is not valid, so the same Textpaint class
The specific 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 antialiasing and use device text kerning textpaint textpaint = new Textpaint (Paint. ANTI_alias_flag | Paint. DEV_kern_text_flag); font-related Settings textpaint. Settextsize(35.0F;//font sizeTextpaint. Settypeface(Typeface. DEFAULT_bold); Textpaint. SetColor(Color. BLACK); Textpaint. Setshadowlayer(3F1,1, context. Getresources(). GetColor(Android. R. Color. Background_dark)); Staticlayout layout = new Staticlayout (water, Textpaint, -, Alignment. ALIGN_normal,1.0F0.0F, True); Canvas. Save(); Canvas. Translate(float) (w*0.05), (float) (h*0.9));//Start drawing from 20, 20Layout. Draw(canvas); Canvas. Save(Canvas. All_save_flag); Return Tarbitmap; }

One of the parameters in Staticlayout is 500, which is to set how long to start the line break.

Android to achieve image plus watermark

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.