目前已经能写成这样了
本人用了FrameLayout布局,下面的图片是一个ImageView,上面是本人一个自定义的View,代码如下:
public class MyView extends View{ public MyView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); Canvas c1 = new Canvas(bitmap); c1.drawARGB(150, 0, 0, 0); Paint strokePaint = new Paint(); strokePaint.setAntiAlias(true); strokePaint.setColor(Color.WHITE); strokePaint.setStyle(Paint.Style.STROKE); strokePaint.setStrokeWidth(2); c1.drawCircle(getWidth() / 2, getHeight() / 2, 100, strokePaint); //画圆 Bitmap circleBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); Canvas c2 = new Canvas(circleBitmap); Paint circlePaint = new Paint(); circlePaint.setStyle(Paint.Style.FILL); circlePaint.setColor(Color.RED); circlePaint.setAntiAlias(true); c2.drawCircle(getWidth() / 2, getHeight() / 2, 100, circlePaint); //两个图层合成 Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); c1.drawBitmap(circleBitmap, 0, 0, paint); paint.setXfermode(null); canvas.drawBitmap(bitmap, 0, 0, null); } }
现在想问一下一下各位前辈,怎么样截取圆形中的图案,前辈给个提示
解决方案
20
Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height)
前提是你要知道你当前圆圆心所在位置,不如圆的半径为100,现在圆形在300,300点
那么bitmap=Bitmap.createBitmap(原图片, 300-100, 300-100, 200, 200) ;
就会得到一个200*200的bitmap 正好圆的直径也是200
前提是你要知道你当前圆圆心所在位置,不如圆的半径为100,现在圆形在300,300点
那么bitmap=Bitmap.createBitmap(原图片, 300-100, 300-100, 200, 200) ;
就会得到一个200*200的bitmap 正好圆的直径也是200