zxingでバーコードスキャンをサポート

4629 ワード

ZXingを変更してバーコードスキャンをサポートする方法.
1. - (IBAction)scanPressed:(id)sender   :
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:YES];


MultiFormatOneDReader *OneReaders=[[MultiFormatOneDReader alloc]init]; QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init]; NSSet *readers = [[NSSet alloc ] initWithObjects:OneReaders,qrcodeReader,nil]; 
[qrcodeReader release]; 
[OneReaders release];
2. ZXingWidgetController.m  (void)captureOutput:(AVCaptureOutput *)captureOutput :   ,       

  if (oneDMode) {
    //let's just give the decoder a vertical band right above the red line
    cropRect.origin.x = cropRect.origin.x + (cropRect.size.width/ 2) - (ONE_D_BAND_HEIGHT + 1);
    cropRect.size.width = ONE_D_BAND_HEIGHT;
    //do a rotate
    CGImageRef croppedImg = CGImageCreateWithImageInRect(capture, cropRect);
    capture = [self CGImageRotated90:croppedImg];
    capture = [self CGImageRotated180:capture];
    //              UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:capture], nil, nil, nil);
    CGImageRelease(croppedImg);
    cropRect.origin.x = 0.0;
    cropRect.origin.y = 0.0;
    cropRect.size.width = CGImageGetWidth(capture);
    cropRect.size.height = CGImageGetHeight(capture);
  }
3. 
上に注記したコードを下に約20行のコードにします.
UIImage *scrn = [[UIImage alloc] initWithCGImage:newImage]; 
  :
int backCameraImageOrientation = UIImageOrientationRight; 
UIImage *scrn = [[UIImage alloc] initWithCGImage:newImage scale: 
(CGFloat)1.0 orientation:backCameraImageOrientation];

4. 
OverlayViewでmコメントコード以下のコード:
self.oneDMode = isOneDModeEnabled;