0
-(void)decode:(CVImageBufferRef)BufferRef
{

  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

  CGImageRef videoFrameImage = [ZXCGImageLuminanceSource createImageFromBuffer:BufferRef];

  CGImageRef rotatedImage = [self rotateImage:videoFrameImage degrees:0.0f];

  [NSMakeCollectable(videoFrameImage) autorelease];

  //Decoding:
  ZXLuminanceSource* source = [[[ZXCGImageLuminanceSource alloc]     initWithCGImage:rotatedImage] autorelease];

  [NSMakeCollectable(rotatedImage) autorelease];

  ZXBinaryBitmap* bitmap = [ZXBinaryBitmap binaryBitmapWithBinarizer:[ZXHybridBinarizer binarizerWithSource:source]];

  NSError* error = nil;

  // There are a number of hints we can give to the reader, including

  // possible formats, allowed lengths, and the string encoding.

  ZXDecodeHints* hints = [ZXDecodeHints hints];

  ZXMultiFormatReader* reader = [ZXMultiFormatReader reader];

  ZXResult* result = [reader decode:bitmap
                              hints:hints
                              error:&error];
  if (result) 
  {

    // The coded result as a string. The raw data can be accessed with

    // result.rawBytes and result.length.

    NSString* contents = result.text;

    // The barcode format, such as a QR code or UPC-A

    ZXBarcodeFormat format = result.barcodeFormat;

  } 

  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.
  }


  [pool drain];

}
4

2 に答える 2

1

この問題は、カメラが生成する画像をダウンサンプリングすることで簡単に解決できます。ライブラリがバーコードを処理するには解像度が高すぎるようです。[image CGImage] を呼び出す前に UIImage のサイズを 640x480 に縮小すると、すべてが完全に機能しました。

于 2013-04-11T02:30:47.987 に答える
0

エラーを使用して結果が得られなかった理由を判断する必要があるとコメントしましたが、実際にはそうしていません。にあるものを見てくださいerror

于 2012-09-07T11:08:16.003 に答える