如何使用Zbar裁剪扫描的条形码? [英] How to crop scanned barcode using Zbar?

查看:120
本文介绍了如何使用Zbar裁剪扫描的条形码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码使用Zbar sdk扫描条形码。

I am using below code to scan bar code using Zbar sdk.

我通过 stackoverflow的相关问题但该答案对我不起作用。

I go through related question of stackoverflow but that answer is not working for me.

直到现在我已经完成了,

Till now I have done,

-(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方法正在裁剪,

advanceCrop Method is doing crop,

-(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?

If I am getting Image as below and I want to crop it, is it possible with Zbar?

推荐答案

试试这个。如果 CGRect = CGRectMake(x,y,width,height); ,则执行:

Try this. If CGRect = CGRectMake(x, y, width, height);, then do:

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 );

这篇关于如何使用Zbar裁剪扫描的条形码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆