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.