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