标签:
//添加文字水印
//src 原始图片
//watermark 水印图片
//title 水印文字
private Bitmap createBitmap(Bitmap src,Bitmap watermark,String title){
if (src == null){
return null;
}
//获取原始图片的宽和高
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 ="宋体";
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);
//这里是自动换行的
StaticLayout layout = new StaticLayout(title,textPaint,w, Layout.Alignment.ALIGN_NORMAL,1.0F,0.0F,true);
layout.draw(cv);
//此方法可调整文字位置
//cv.drawText(title,0,380,textPaint);
}
cv.save(Canvas.ALL_SAVE_FLAG);// 保存
cv.restore();// 存储
return newb;
}
标签:
原文地址:http://www.cnblogs.com/zhangminghan/p/5476548.html