【发布时间】:2012-02-19 11:14:33
【问题描述】:
我想通过我的 iPhone 应用程序中的前置摄像头以编程方式拍照 我不希望用户选择图像选择器或与图像选择器进行任何交互..只想拍摄图像并将其保存在文档中..这可能吗?
【问题讨论】:
我想通过我的 iPhone 应用程序中的前置摄像头以编程方式拍照 我不希望用户选择图像选择器或与图像选择器进行任何交互..只想拍摄图像并将其保存在文档中..这可能吗?
【问题讨论】:
从您的问题中我可以理解,AV Foundation 就是您所需要的。 看看这个来自 Apple 的演示源:AVCam
【讨论】:
编辑:我的错,看来您实际上可以从 AVCaptureSession 中做到这一点。虽然我无法理解为什么这应该是可能的。对我来说,这似乎是一个潜在的滥用理由。
原始(错误)答案: 不,无论是前置摄像头还是后置摄像头,都无法在没有用户交互的情况下拍照。
【讨论】:
试试这个——
- (IBAction) scanButtonTapped
{
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentModalViewController: reader
animated: YES];
[reader release];
}
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
// EXAMPLE: do something useful with the barcode data
resultText.text = symbol.data;
bid.text=symbol.data;
// EXAMPLE: do something useful with the barcode image
resultImage.image =
[info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
}
【讨论】: