我正在使用以下代码来解码从相机拍摄的 QRCode
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
ZXQRCodeReader *reader = [[ZXQRCodeReader alloc]init];
ZXLuminanceSource *source = [[ZXCGImageLuminanceSource alloc] initWithCGImage:[originalImage CGImage]];
ZXHybridBinarizer *binazer = [ZXHybridBinarizer binarizerWithSource:source];
ZXBinaryBitmap *bitmap = [[ZXBinaryBitmap alloc]initWithBinarizer:binazer];
NSError *error;
ZXResult *result = [reader decode:bitmap
hints:nil
error:&error];
if(result){
[[[UIAlertView alloc] initWithTitle:@"Success" message:@"Success"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil] show];
} else {
// Use error to determine why we didn't get a result, such as a barcode
// not being found, an invalid checksum, or a format inconsistency.
[[[UIAlertView alloc] initWithTitle:@"ERROR" message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil] show];
}
但是,我收到一条错误消息,指出在 Image 上找不到条形码。另一方面,如果我使用 ZXingObjC 提供的测试图像,它可以工作,问题只是在尝试 UIImagePickerController 图像时。所以有什么想法可能是错的???
非常感谢。