问题
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