android中给图片打水印

/**
  *
  * @param src 原图片
  * @param watermark  要打的水印图片
  * @return Bitmap 打好水印的图片
  */
 private Bitmap createBitmap(Bitmap src,Bitmap watermark){
  if(src == null){
   return null;
  }
  int srcWidth = src.getWidth();
  int srcHeight = src.getHeight();
  
  int waterWidth = watermark.getWidth();
  int waterHeight = watermark.getHeight();
  //create the new blank bitmap
  Bitmap newb = Bitmap.createBitmap(srcWidth,srcHeight,Config.ARGB_8888);//创建一个新的和src长度宽度一样的位图
  Canvas cv = new Canvas(newb);
  cv.drawBitmap(src, 0, 0,null);//在0,0坐标开始画入src
  /*Paint paint = new Paint();
  paint.setColor(Color.RED);*/
  if(watermark != null){
   cv.drawBitmap(watermark, srcWidth-waterWidth,srcHeight-waterHeight, null);//在src的右下解画入水印图片
   //cv.drawText("HELLO",srcWidth-waterWidth,srcHeight-waterHeight, paint);//这是画入水印文字,在画文字时,需要指定paint
  }
  cv.save(Canvas.ALL_SAVE_FLAG);//保存
  cv.restore();//存储
  return newb;
 }

运行效果:

android中给图片打水印