如何使用 Zbar 裁剪扫描的条码?

2024-04-14移动开发问题
5

本文介绍了如何使用 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 裁剪扫描的条码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7