create Bitmap For Watermark - Android Graphics

Android examples for Graphics:Bitmap Paint

Description

create Bitmap For Watermark

Demo Code


import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;

public class Main {

  public static Bitmap createBitmapForWatermark(Bitmap src, Bitmap watermark) {
    if (src == null) {
      return null;
    }/*from   w ww .  ja va2 s  .co m*/
    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, Config.ARGB_8888);// SRC
    Canvas cv = new Canvas(newb);
    // draw src into
    cv.drawBitmap(src, 0, 0, null);// 00src
    // draw watermark into
    cv.drawBitmap(watermark, w - ww + 5, h - wh + 5, null);// src
    // save all clip
    cv.save();//
    // store
    cv.restore();//
    return newb;
  }
}

Related Tutorials