我正在编写iphone应用程序,我想要qr代码扫描。我有QR码库来扫描QR码。现在我想给我的iPhone应用程序提供二维码扫描界面。
在Android中,我可以使用SurfaceView
来实现这一点,{{1}}是我们可以显示相机帧的视图。 iPhone中与surfaceview相同的iPhone有什么可用吗?如果是这样的话怎么做。请给我一个教程或示例链接。
答案 0 :(得分:1)
- (IBAction)TakePicture:(id)sender {
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
// Insert the overlay:
imagePicker.cameraOverlayView = overlay;
// Allow editing of image ?
imagePicker.allowsImageEditing = YES;
[imagePicker setCameraDevice:
UIImagePickerControllerCameraDeviceFront];
[imagePicker setAllowsEditing:YES];
imagePicker.showsCameraControls=YES;
imagePicker.navigationBarHidden=YES;
imagePicker.toolbarHidden=YES;
imagePicker.wantsFullScreenLayout=YES;
self.library = [[ALAssetsLibrary alloc] init];
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}
创建一个UIView类并添加此代码
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
// Clear the background of the overlay:
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
// Load the image to show in the overlay:
UIImage *overlayGraphic = [UIImage imageNamed:@"overlaygraphic.png"];
UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
overlayGraphicView.frame = CGRectMake(30, 100, 260, 200);
[self addSubview:overlayGraphicView];
}
return self;
}
您也可以参考以下链接:http://www.musicalgeometry.com/?p=821
答案 1 :(得分:0)
自iOS 7以来,iOS中的QR代码检测功能很快就可以使用,其诀窍是告诉AVCaptureMetadataOutput
实例检测类型为AVMetadataObjectTypeQRCode
的对象。
实时相机预览(如果您仍想使用,则可访问像素)在iOS中很长一段时间,最简单的AVCaptureVideoPreviewLayer
。