Creating canvas on top of SurfaceView android

前提是你 提交于 2021-01-29 20:08:49

问题


I am trying to create canvas like the below image on the top SurfaceView using which i will open the camera

This rectangular canvas should support every screen size in android and should be at center_vertical and center_horizontal of the screen with rest of the screen as translucent black as displayed in the image. I am very new with Canvas and have tried this:

Java:

package com.example.cameraapplication;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class MyView extends View {
    public MyView(Context context) {
        super(context);
    }


    @Override
    protected  void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.GREEN);
        canvas.drawRect(
                getLeft()+(getRight()-getLeft())/3,
                getTop()+(getBottom()-getTop())/3,
                getRight()-(getRight()-getLeft())/3,
                getBottom()-(getBottom()-getTop())/3,paint);

        super.onDraw(canvas);
    }
}

but it is not working out. So anyone please tell me how should i create the canvas like this and also i want to crop the captured image's rectangular part. So please try to help me with both or one problem at least.

来源:https://stackoverflow.com/questions/61746044/creating-canvas-on-top-of-surfaceview-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!