Hi, I have days trying to solve the following issue.
In the application that I am currently developing, I must cut the area inside the rectangle that I show in the perview of the camera as shown below.
What do I have?
the preview class
public class CapturePreview extends SurfaceView implements SurfaceHolder.Callback{
public static Bitmap mBitmap;
SurfaceHolder holder;
static Camera mCamera;
private final Paint paint;
public CapturePreview(Context context, AttributeSet attrs) {
super(context, attrs);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
holder = getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
Camera.Parameters parameters = mCamera.getParameters();
parameters.getSupportedPreviewSizes();
mCamera.setParameters(parameters);
mCamera.setDisplayOrientation(90);
mCamera.startPreview();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
mCamera = Camera.open();
mCamera.setPreviewDisplay(holder);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mCamera.release();
}
public static void takeAPicture(){
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
BitmapFactory.Options options = new BitmapFactory.Options();
mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options);
}
};
mCamera.takePicture(null, null, mPictureCallback);
}
in my fragment tab1_framgent.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.ccsdeveloment.visitascontrol.CapturePreview
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- overlay - customize padding and stuff -->
<View
android:layout_width="600dp"
android:layout_height="400dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="316dp"
android:background="@drawable/rect"
android:padding="32dp" />
</RelativeLayout>
Rect.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="3dp"
android:color="@color/colorPrimaryDark"
android:dashGap="8dp"
android:dashWidth="8dp" />
<corners android:radius="8dp" />
</shape>
What am I trying to do?
try to capture the photo either by a button or by ontouchevent only take the section inside the rectangle. I would like to know how this is possible and also if you can leave the rest of the area outside the rectangle a transparent shadow
a shading similar to this
Thanks in advance to those people who can help me I have been reading some questions in the Stackoverflow community in English I have tried some but I have not come up with a solution ... I understand or I think I understand that this is achieved with a surfaceview but not I understand its implementation well.