Add a text watermark
SRC Original image
Watermark Watermark Picture
Title Watermark Text
Private Bitmap CreateBitmap (Bitmap src,bitmap watermark,string title) {
if (src = = null) {
return null;
}
Get the width and height of the original picture
int w = src.getwidth ();
int h = src.getheight ();
Bitmap newb= Bitmap.createbitmap (W, H, Bitmap.Config.ARGB_8888);
Canvas CV = new canvas (NEWB);
Cv.drawbitmap (SRC, 0, 0, NULL);
if (title!=null)
{
String familyname = "Song Body";
Typeface font = typeface.create (familyname,typeface.bold);
Textpaint textpaint=new textpaint ();
Textpaint.setcolor (Color.Black);
Textpaint.settypeface (font);
Textpaint.settextsize (35);
Textpaint.setfakeboldtext (TRUE);
Textpaint.settextalign (Paint.Align.CENTER);
Cv.translate (580,550);
This is a line wrap.
Staticlayout layout = new Staticlayout (title,textpaint,w, layout.alignment.align_normal,1.0f,0.0f,true);
Layout.draw (CV);
This method can adjust the text position
Cv.drawtext (Title,0,380,textpaint);
}
Cv.save (Canvas.all_save_flag);//Save
Cv.restore ();//Storage
return newb;
}
Add a text watermark to a picture