所以,我已经成功创建了一个带有矩形区域的相机,它看起来像这样:
这是我如何使用自定义视图绘制矩形
@Override
protected void onDraw(Canvas canvas) { // Override the onDraw() Method
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.GREEN);
paint.setStrokeWidth(10);
//draw guide box
canvas.drawColor(Color.TRANSPARENT);
canvas.drawRect(
getLeft()+50,
getTop()+(getBottom()-getTop())/3,
getRight()-50,
getBottom()-(getBottom()-getTop())/3,paint);
super.onDraw(canvas);
}
输出:
我只需要绿色矩形内的内容,我尝试在保存存储之前对其进行裁剪,并且输出看起来像这样:
用于将此package
中的catchStillPicture()内裁剪的代码Rect cropRect = new Rect(mTextureView.getLeft()+50,
mTextureView.getTop()+(mTextureView.getBottom()-mTextureView.getTop())/3,
mTextureView.getRight()-50,
mTextureView.getBottom()-(mTextureView.getBottom()-mTextureView.getTop())/3);
// Use the same AE and AF modes as the preview.
captureBuilder.set(CaptureRequest.SCALER_CROP_REGION, cropRect);
//End Add
输出:
你们能帮我把图片放在矩形内吗?我该怎么做呢?