【发布时间】:2019-10-12 19:35:39
【问题描述】:
我正在使用 Camera api 捕捉身份证图片,我有一个覆盖,如下图所示。我想裁剪框中的图像。你能建议它应该如何完成吗?我已经写下了我尝试过的东西以及它给我的结果。
这是我要截取的id的截图..
输出。
白色矩形框是相框,位于相对布局的中心
<View
android:id="@+id/photo_frame"
android:layout_width="match_parent"
android:layout_height="212dp"
android:background="@drawable/bg_photo_frame"
android:layout_centerInParent="true"
android:layout_margin="@dimen/double_padding"
android:visibility="visible"/>
我如何计算这个帧来剪切图像
这是我必须剪切需要修改但不确定前进方向的图像
public Bitmap cutImage(final Bitmap srcBmp, final int pixepWidth, final int pixelsHeight, float widthRatio) {
// Bitmap croppedBitmap = Bitmap.createBitmap(bitmap, 20, 20, pixepWidth, pixelsHeight);
// return croppedBitmap;
Bitmap dstBmp;
if (srcBmp.getWidth() >= srcBmp.getHeight()){
dstBmp = Bitmap.createBitmap(
srcBmp,
srcBmp.getWidth()/2 - srcBmp.getHeight()/2,
0,
srcBmp.getHeight(),
srcBmp.getHeight()
);
}else{
dstBmp = Bitmap.createBitmap(
srcBmp,
0,
srcBmp.getHeight()/2 - srcBmp.getWidth()/2,
srcBmp.getWidth(),
srcBmp.getWidth()
);
}
return dstBmp;
}
【问题讨论】:
标签: android bitmap android-camera android-bitmap android-camera2