c# - Xamarin.Forms VNDocumentCameraViewController Scanner如何在Android中实现类似
问题描述
我在我的 Xamarin.Forms 应用程序中实现了 IOS 13+ Vision 支持的 Document Scanner。这是我的 IOS SharedFunction 代码
[assembly: Dependency(typeof(CameraScanner))]
class CameraScanner : ICameraScanner
{
public void OpenScanCamera()
{
ScanViewController viewController = new ScanViewController();
UIApplication.SharedApplication.KeyWindow.RootViewController.
PresentViewController(viewController, false, null);
}
public static UIKit.UIViewController GetTopViewController()
{
var window = UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
while (vc.PresentedViewController != null)
vc = vc.PresentedViewController;
if (vc is UINavigationController navController)
vc = navController.ViewControllers.Last();
return vc;
}
}
VNDocumentCameraViewController 类逻辑,用于制作 IOS Vision 支持的拍照和扫描视图
[Register("UniversalView")]
public class UniversalView : UIView
{
public UniversalView()
{
Initialize();
}
public UniversalView(RectangleF bounds) : base(bounds)
{
Initialize();
}
void Initialize()
{
BackgroundColor = UIColor.Blue;
}
}
[Register("ScanViewController")]
public class ScanViewController : UIViewController
{
public ScanViewController()
{
}
public override void DidReceiveMemoryWarning()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad()
{
View = new UniversalView();
base.ViewDidLoad();
// Perform any additional setup after loading the view
}
public override void ViewDidAppear(bool animated)
{
var documentCameraController = new VNDocumentCameraViewController();
var documentscanDelegate = new DocumentScanDelegate();
documentscanDelegate.OnScanTaken += (VNDocumentCameraScan scan) =>
{
documentCameraController.DismissViewController(true, null);
Debug.WriteLine($"{scan.PageCount} Pages!");
};
documentscanDelegate.OnCanceled += () =>
{
documentCameraController.DismissViewController(true, null);
};
documentCameraController.Delegate = documentscanDelegate;
documentCameraController.ModalPresentationStyle = UIModalPresentationStyle.OverFullScreen;
PresentViewController(documentCameraController, true, null);
}
}
class DocumentScanDelegate : VNDocumentCameraViewControllerDelegate
{
public delegate void ScanTakenEventHandler(VNDocumentCameraScan scan);
public event ScanTakenEventHandler OnScanTaken;
public delegate void ScanCanceledEventHandler();
public event ScanCanceledEventHandler OnCanceled;
public override void DidCancel(VNDocumentCameraViewController controller)
{
Debug.WriteLine("DocumentScanDelegate:DidCancel");
OnCanceled();
}
public override void DidFinish(VNDocumentCameraViewController controller, VNDocumentCameraScan scan)
{
Debug.WriteLine("DocumentScanDelegate:DidFinish");
OnScanTaken(scan);
}
public override void DidFail(VNDocumentCameraViewController controller, NSError error)
{
Debug.WriteLine("Failed scanning photo");
}
}
}
哪个是类似的实现Xamarin.Android
?我知道谷歌也支持相机扫描,但我找不到关于它的好文档。有人进口过这个吗?
解决方案
推荐阅读
- c# - 无法使用 Lambda 表达式显式加载导航属性
- java - Hibernate PessimisticLockingFailureException 每天特定时间发生
- javascript - 反转字符串中的单词时没有得到我想要的顺序
- android - Kotlin Coroutines - 返回流的暂停函数永远运行
- java - 后台服务在睡眠模式下无法在 Android 中运行
- javascript - 获取表格每一行的复选框总和
- twilio - 是否有可能添加时间限制
- rest - RESTFul API 复杂对象创建回滚
- python - 如何在熊猫中使用 r 的 seq 函数
- r - “匹配错误:'匹配'需要 R Shiny 中的向量参数