今天在项目中遇到一个问题,就是在图片上加上水印效果,刚拿到想过,很蒙圈,现在解决了 ,记录一下demo.
生成图片水印的过称步骤:载入原始图片,载入水印图片,保存新的图片
public class CreateBitmap{public static Bitmap CreateBitmap(Bitmap src,Bitmap watermark){
if(src ==null){
return null;
}
int w = src.getWidth();
int height = src.getHeight();
int ww =watermark.getWidth();
int wh = watermark.getHeight();
//create the new blank bitmap
Bitmap newBitmap = Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);
Pain p = new Pain();
Canvas cv = new Canvas(newBitmap);
cv.drawBitmap(src,0,0,p)//在0.0坐标开始画入水印
cv.drawBitmap( watermark, w - ww -200, h - wh - 240, p );//在src的右下角画入水印
// cv.drawBitmap(watermark,30,30,p);//在src的右下角画入水印
//save all clip
cv.save( Canvas.ALL_SAVE_FLAG );//保存
//store
cv.restore();//存储
return newb;
}
}