【问题标题】:How to crop scanned barcode using Zbar?如何使用 Zbar 裁剪扫描的条码?
【发布时间】:2012-01-04 11:48:24
【问题描述】:

我正在使用下面的代码使用 Zbar sdk 扫描条形码。

我通过related question of stackoverflow 但那个答案对我不起作用。

到目前为止,我已经完成了,

-(IBAction)btnCLick
    {
        ZBarReaderViewController *reader = [ZBarReaderViewController new];
        reader.readerDelegate = self;
        reader.supportedOrientationsMask = ZBarOrientationMaskAll;

        ZBarImageScanner *scanner = reader.scanner;
        [scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];


        [self presentModalViewController:reader animated:YES];
        [reader release];
    }

- (void) imagePickerController: (UIImagePickerController*) aReader
     didFinishPickingMediaWithInfo: (NSDictionary*) info
    {

        id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];

        ZBarSymbol *symbol = nil;

        for(symbol in results)
        {
            break;
        }
        txtViewResult.text = symbol.data;
        imgViewResult.image = [info objectForKey:UIImagePickerControllerOriginalImage];

        [self advanceCrop:imgViewResult];
        [reader dismissModalViewControllerAnimated:YES];

    }

advanceCrop 方法正在做裁剪,

-(void)advanceCrop:(UIImageView *)aimgViewResult
    {


        CGRect r =CGRectMake(50/426., 1-(20+250)/320., 150/426., 250/320.);
        reader.scanCrop = r;


        r = CGRectMake(20, 50, 250, 150);

        imgViewResult.frame = r;
        NSLog(@"imgview height:%f width:%f",imgViewResult.frame.size.height, imgViewResult.frame.size.width);


        /*

       // CGRect r = CGRectFromString(lblImage.text);
       CGRect r = CGRectMake(50/426., 1-(20+250)/320., 150/426., 250/320.);

        reader.scanCrop = r; 
        NSLog(@"r: x:%f  y:%f height :%f  width:%f",r.origin.x ,r.origin.y ,r.size.height , r.size.width);

       // aLblImage.text = NSStringFromCGRect(r);

        r.origin.x *= 426;
        r.origin.y *= 320;
        r.size.width *= 426;
        r.size.height *= 320;

        imgViewResult.frame = r;
        NSLog(@"imgview height:%f width:%f",imgViewResult.frame.size.height, imgViewResult.frame.size.width);
         */
    }

如果我得到如下图像并且我想裁剪它,Zbar 可以吗?

【问题讨论】:

    标签: iphone ios5 uiimageview zbar-sdk


    【解决方案1】:

    试试这个。如果CGRect = CGRectMake(x, y, width, height);,那么做:

    float A = y / readerView.bounds.size.height;   
    float B = 1 - (x + width) / readerView.bounds.size.width;   
    float C = (y + height) / readerView.bounds.size.height;   
    float D = 1 - x / readerView.bounds.size.width;;  
    CGRectMake( A, B, C, D );
    

    【讨论】:

      猜你喜欢
      • 2013-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      相关资源
      最近更新 更多