try {
ImageView img=(ImageView) findViewById(R.id.test_img_file);
//获取从本地获取的文件路径,用FileInputstream读入文件,并将图片文件转换成位图
Bundle bundle=getIntent().getExtras();
String path=bundle.getString("test");
FileInputStream fa=new FileInputStream(path);
Bitmap bm=BitmapFactory.decodeStream(fa);//原图
Bitmap wm=BitmapFactory.decodeResource(getResources(), R.drawable.wate_market);//水印
//将creatBitmap()方法的返回值(返回位图)放到图片控件显示
img.setImageBitmap(createBitMap(bm,wm));
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
private Bitmap createBitMap(Bitmap src,Bitmap wmsrc){
/**
* 水印制作方法
*/
String tag="xx";
Log.d(tag, "开始了,画图");
if(src==null){
return null;
}
int w=src.getWidth();
int h=src.getHeight();
int wmw=wmsrc.getWidth();
int wmh=wmsrc.getHeight();
//create the new bitmap
Bitmap newb=Bitmap.createBitmap(w,h,Config.ARGB_8888);//创建一个底图
Canvas cv=new Canvas(newb);
//将底图画进去
cv.drawBitmap(src, 0, 0,null);//在0,0坐标开始画入src
//讲水印画进去
cv.drawBitmap(wmsrc, w-wmw+5, h-wmh+5, null);
//保存图片
cv.save(Canvas.ALL_SAVE_FLAG);
cv.restore();
return newb;
}
}