Android创建新的bitmap带水印

项目中需要做截图操作,然后在新的图片上,加上log,所以写的方法记录一下,方便使用查找。
public class CreateBitmap {
public static Bitmap createBitmap(Bitmap src, Bitmap watermark){
String tag = "createBitmap";
Log.d( tag, "create a new bitmap" );
if( src == null ) {
return null;
}
int w = src.getWidth();
int h = src.getHeight();
int ww = watermark.getWidth();
int wh = watermark.getHeight();
//create the new blank bitmap
Bitmap newb = Bitmap.createBitmap( w,h, Bitmap.Config.ARGB_8888 );
Paint p = new Paint();
Canvas cv = new Canvas( newb );
//draw src into
cv.drawBitmap( src, 0, 0,p );//在 0,0坐标开始画入src
//draw watermark into//
cv.drawBitmap( watermark, w - ww + 5, h - wh + 5, p );
//在src的右下角画入水印
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;
}
}

你可能感兴趣的:(Android创建新的bitmap带水印)