public Bitmap cutPic(Bitmap bitmap){
Bitmap mImage=bitmap;
Bitmap mMask=null;
Bitmap mImageChanged=null;
Bitmap result=null;
//s_massege_hw是你用作图工具做出的形状图片
mMask=BitmapFactory.decodeResource(getResources(), R.drawable.s_massege_hw);
Matrix matrix = new Matrix();
matrix.postScale((float)mMask.getWidth()/(float)mImage.getWidth(),(float)mMask.getHeight()/(float)mImage.getHeight() );
//将图片缩放到和形状图片一样的大小
mImageChanged = Bitmap.createBitmap(mImage, 0, 0, mImage.getWidth(),mImage.getHeight(), matrix, true);
result = Bitmap.createBitmap(mMask.getWidth(),mMask.getHeight(), Config.ARGB_8888);
Canvas mCanvas = new Canvas(result);
Paint paint =new Paint();
paint.setColor(0xffffffff);
paint.setAntiAlias(true);
//切割模式,取交集上层
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
mCanvas.drawBitmap(mMask, 0, 0, null);
mCanvas.drawBitmap(mImageChanged, 0, 0, paint);
paint.setXfermode(null);
return result;
}
原文链接:http://www.apkbus.com/blog-653697-59420.html
打开App,阅读手记