Tag: 画布

Android – 使用画布在背景颜色之外设置背景颜色

我正在研究Camera Activity Overlay,我已经成功地在矩形外部(不透明的黑色)创建了不透明的颜色。 而且我已经成功地在大矩形内创建了一个小矩形。 请看下面的图片。 正如你所看到的,小矩形上有一个蓝色的背景。 问题是,我想要在图像(位图)之外制作蓝色背景,而不是覆盖图像。 问题是,如果我用透明填充来改变图像,那么蓝色的背景将会覆盖全部。 我怎样才能使蓝色背景只覆盖图像的外部? 我已经试图从谷歌找到所有可能的答案,但对我来说没有运气,也许我开始用错误的方法,需要咨询。 这是我的代码 bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); Canvas osCanvas = new Canvas(bitmap); RectF outerRectangle = new RectF(0, 0, getWidth(), getHeight()); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(getResources().getColor(R.color.opaque_black)); paint.setAlpha(99); osCanvas.drawRect(outerRectangle, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); paint.setColor(Color.TRANSPARENT); paint.setStyle(Paint.Style.FILL); RectF r1 = new RectF( (float) (xStartingPoint), (float) (yStartingPoint), (float) (parentWidth), (float) (parentHeight)); […]

自定义视图不是在Android中绘制的

我为我的android应用程序实现自定义按钮,其中必须只有没有填充的圆。 我在Android开发的这个方面比较新,所以我遇到了麻烦。 有自定义属性: <resources> <declare-styleable name="CircleButton"> <attr name="stroke_width" format="dimension"/> </declare-styleable> 班级代码: class CircleButton (context: Context, attrs: AttributeSet) : View(context, attrs) { val paint: Paint = Paint() init { var a = context.theme.obtainStyledAttributes(attrs, R.styleable.CircleButton, 0, 0) paint.color = Color.RED try { paint.strokeWidth = a.getDimension(R.styleable.CircleButton_stroke_width, 3f) } finally { a.recycle() } } var centerX = x + […]