Skip to content

Instantly share code, notes, and snippets.

@tank777
Last active September 21, 2017 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tank777/caceabc8bd29b252666c2c97a7401b78 to your computer and use it in GitHub Desktop.
Save tank777/caceabc8bd29b252666c2c97a7401b78 to your computer and use it in GitHub Desktop.
private Bitmap addWaterMark(Bitmap src, Bitmap waterMark) {
if (src == null || waterMark == null) {
return null;
}
try {
int w = src.getWidth();
int h = src.getHeight();
Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);
//int watermarkPadding = 30;
int newWatermarkWidth = w / 5;
int newWatermarkHeight = (waterMark.getHeight() * newWatermarkWidth) / waterMark.getWidth();
Bitmap newWatermark = Bitmap.createScaledBitmap(waterMark, newWatermarkWidth, newWatermarkHeight, true);
canvas.drawBitmap(newWatermark, 0, h - newWatermarkHeight, null);
// canvas.drawBitmap(waterMark, 0, 0, null);
return result;
} catch (Exception ex) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment