I want to add water mark to image in android app. In my app user can select a image and write text in a edit text,after pressing a button i want selected image with watermark text on it. I have try below code but it is not working.
public static void mark(String watermark,String filePath) {
try{
Bitmap bmp = BitmapFactory.decodeFile(filePath);
int w = bmp.getWidth();
int h = bmp.getHeight();
Bitmap result = Bitmap.createBitmap(100, 100, bmp.getConfig());
Canvas canvas = new Canvas(result);
canvas.drawBitmap(bmp, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setAlpha(40);
paint.setTextSize(20);
paint.setAntiAlias(true);
canvas.drawText(watermark,w/2, h/2+20, paint);
File nFile = new File(getDevicePath(mContext)+"output1.jpg");
nFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(nFile);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
}
catch(Exception e){
e.printStackTrace();
}
}
please give me the way to solve above problem.
Thanks in advance.