赞
踩
1、PorterDuffXfermode
用法:设置两张图片相交时的模式
例子:
mPaint = newPaint();
mPaint.setXfermode( newPorterDuffXfermode(PorterDuff.Mode.SCREEN));
常见的Xfermode(SRC为原图,DST为目标图),把代码中的SRC_IN换成下图指定的模式就会出现对应的效果图。
Canvas canvas = newCanvas(Src);
paint.setXfermode( newPorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(Dst, 0f, 0f, paint);
2、制作圆形图片
// 将图片做成圆形的
public Bitmap toOvalBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getHeight(),
bitmap.getWidth(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
RectF rectF = new RectF(rect);
canvas.drawOval(rectF, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rectF, paint);
return output;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。