问题描述
在我的应用程序中,我必须捕获国家ID(与信用卡大小相同),并将图像传递给后端。我尝试了以下代码在相机应用程序中显示矩形叠加层:
return Container(
height: MediaQuery.of(context).size.height,child: Stack(
children: <Widget>[
CustomPaint(
foregroundPainter: Paint(),child: CameraPreview(controller),),ClipPath(
clipper: Clip(),child: CameraPreview(controller)),],);
}
class Paint extends CustomPainter{
@override
void paint(Canvas canvas,Size size) {
canvas.drawColor(Colors.grey.withOpacity(0.8),BlendMode.dstOut);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
// Todo: implement shouldRepaint
return true;
}
}
class Clip extends CustomClipper<Path>{
@override
getClip(Size size) {
print(size);
Path path = Path()
..addRRect(RRect.fromrectAndRadius(Rect.fromLTWH(10,size.height/2-120,size.width-20,260),Radius.circular(26)));
return path;
}
@override
bool shouldReclip(oldClipper) {
// Todo: implement shouldReclip
return true;
}
现在我可以显示覆盖了(PFB屏幕截图)。
然后我在浏览下一个屏幕...绕过图像路径
Navigator.push(
context,MaterialPageRoute(
builder: (context) => CropImageScreen(imagePath: path),);
我在这里尝试裁剪图像。但是图像的高度和宽度不正确。通常在纵向模式下,高度应该更大,宽度应该更少。
但是我的身高是720,宽度是1280。
ImageProperties properties =
await FlutterNativeImage.getimageProperties(imagePath);
final height = properties.height;
final width = properties.width;
print("1. height is: $height");
print("2. Width is: $width");
// I have used some static values to crop the image
File croppedFile = await FlutterNativeImage.cropImage(
imagePath,250,40,properties.width - 500,640);
final originalFile = croppedFile;
List<int> imageBytes = await originalFile.readAsBytes();
final originalImage = img.decodeImage(imageBytes);
但是我的问题是如何使用动态值裁剪图像。我在上面输入的静态值可能适用于我的Samsung设备。但是这些值不适用于其他设备。
还有其他好的方法可以裁剪矩形叠加层中的图像吗?
注意:我已经使用了“ package:camera / camera.dart”库。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)