二维码 _相册

#pragma mark --  二维码扫描//----------------------------------------------------------------------------------------------------

#pragma mark -- 二维码扫描

- (void)QRCode

{

    /*

     扫描二维码部分:

     导入ZBarSDK文件并引入一下框架

     AVFoundation.framework

     CoreMedia.framework

     CoreVideo.framework

     QuartzCore.framework

     libiconv.dylib

     引入头文件#import “ZBarSDK.h” 即可使用

     当找到条形码时,会执行代理方法=

     

     - (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info

     最后读取并显示了条形码的图片和内容。

     */

    ZBarReaderViewController *reader = [ZBarReaderViewController new];

    reader.readerDelegate = self;

    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    //设置自己定义的界面

    [self setOverlayPickerView:reader];

    ZBarImageScanner *scanner = reader.scanner;

    [scanner setSymbology: ZBAR_I25

                   config: ZBAR_CFG_ENABLE

                       to: 0];

    _willDealloc = NO;//不释放

    [self presentViewController:reader

                       animated:YES

                     completion:^{

                     }];

}


#pragma mark -- 二维码扫描

- (void)setOverlayPickerView:(ZBarReaderViewController *)reader

{

    // 清除不需要的控件,并加入自定义的

    for (UIView *temp in [reader.view subviews]) {

        for (UIToolbar *toolbar in [temp subviews]) {

            if ([toolbar isKindOfClass:[UIToolbar class]])

            {

                UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(dismissOverlayView:)];

                UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

                //UIBarButtonItem *item3 = [[UIBarButtonItem alloc]initWithTitle:@"相册" style:UIBarButtonItemStyleBordered target:self action:@selector(clickPhotoToolBarItem:)];

                NSArray *array = [NSArray arrayWithObjects:item1,item2,nil];

                [toolbar setItems:array animated:YES];

            }

        }

    }

    

    UILabel * labIntroudction= [[UILabel alloc] initWithFrame:CGRectMake(15, 40, 290, 50)];

    labIntroudction.backgroundColor = [UIColor clearColor];

    labIntroudction.numberOfLines=2;

    labIntroudction.textColor=[UIColor greenColor];

    [labIntroudction setTextAlignment:NSTextAlignmentCenter];

    [labIntroudction setFont:[UIFont fontWithName:nil size:15]];

    labIntroudction.text=@"请将二维码图像置于矩形方框内,系统会自动识别。";

    [reader.view addSubview:labIntroudction];

    

    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 100, 300, 300)];

    imageView.image = [UIImage imageNamed:@"pick_bg"];

    [reader.view addSubview:imageView];

    

    upOrdown    = NO;

    num         = 0;

    _line       = [[UIImageView alloc] initWithFrame:CGRectMake(50, 110, 220, 2)];

    _line.image = [UIImage imageNamed:@"line.png"];

    [reader.view addSubview:_line];

    timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(animation1) userInfo:nil repeats:YES];

}


#pragma mark -- 二维码扫描动画效果

-(void)animation1

{

    if (upOrdown == NO) {

        num ++;

        _line.frame = CGRectMake(50, 110+2*num, 220, 2);

        if (2*num == 280) {

            upOrdown = YES;

        }

    }else {

        num --;

        _line.frame = CGRectMake(50, 110+2*num, 220, 2);

        if (num == 0) {

            upOrdown = NO;

        }

    }

}


#pragma mark -- 选取相册

-(void)clickPhotoToolBarItem:(id)sender

{

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){

        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

        imagePicker.delegate                 = self;

        imagePicker.allowsEditing            = NO;

        imagePicker.sourceType               = UIImagePickerControllerSourceTypePhotoLibrary;

        [self dismissViewControllerAnimated:NO completion:^{}];

        [self presentViewController:imagePicker animated:YES completion:^{}];

    }

}

#pragma mark -- 取消按钮方法-二维码

- (void)dismissOverlayView:(id)sender{

    [timer invalidate];//释放定时器

    [self dismissViewControllerAnimated:YES completion:^{}];

}

#pragma mark 扫描二维码回调   //当拍照完成后,或者是从相册库选择完一张照片后,调用此方法

- (void) imagePickerController: (UIImagePickerController*) reader

 didFinishPickingMediaWithInfo: (NSDictionary*) info

{

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

    if (results != nil)

    {

        [timer invalidate];      // 释放掉定时器

        ZBarSymbol *symbol = nil;// 是扫描进入的情况

        for(symbol in results)

            break;

        //         self.imageView_Code.image = [info objectForKey: UIImagePickerControllerOriginalImage];

        //        [self dismissViewControllerAnimated:YES

        //                                 completion:^{

        //                                 }];

        NSString *code = [NSString stringWithString:symbol.data];//获取到的数据

        _ktid = code;    //课程id

        

        [self loadDetail];//获取详细信息

        [self dismissViewControllerAnimated:YES completion:^{

        }];

        return;

        //         self.textView_Code.text = code;

    }

        else

        {

    

            // 选择图片的情况

            UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

            [self dismissViewControllerAnimated:YES completion:^{ }];

            ZBarReaderController* read = [ZBarReaderController new];

            read.readerDelegate = self;

            CGImageRef cgImageRef = image.CGImage;

    

            ZBarSymbol* symbol = nil;

            for(symbol in [read scanImage:cgImageRef]) break;

            NSString *code = symbol.data;

            // self.textView_Code.text = code;

        }

    //---------------------------------------------------------------------------

    

    NSString *imageType = [info objectForKey:UIImagePickerControllerMediaType];//判断媒体资源类型,(图片或者是视频)

    if ([imageType isEqualToString:(NSString *)kUTTypeImage]) {//如果是图片资源

        UIImage * image      = [info objectForKey:UIImagePickerControllerEditedImage];

        UIImage * scaleImage = [self scaleImage:image toScale:0.6];

        _ktxcImage.image     = scaleImage;//签到图片

        _ktxcImage.hidden    = NO;

        NSArray *paths       = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

        NSString *filePath   = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"picpic.jpg"]];//保存文件的名称

        _pubImageData        = UIImageJPEGRepresentation(scaleImage, 0.5);//图片按0.75的质量压缩-》转换为NSData

        [_pubImageData writeToFile:filePath atomically:YES];

        // [self upUserHeaderImageData];

        [self dismissViewControllerAnimated:YES completion:^{

        }];

        return;

    }

}

     [YQStuRegHttpTool imagePostWithPath:signUrlStr parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

        [formData appendPartWithFileData:_pubImageData name:@"userpic" fileName:@"picpic" mimeType:@"image/jpeg"];

    } success:^(id json) {

        YQLog(@"%@ %@ \n%@",json,json[@"statusCode"],signUrlStr);

        [self successLoadSign:json];//签到成功

    } failure:^(NSError *error) {

        NSLog(@"%@",error.localizedDescription);

        [SVProgressHUD dismiss];

    }];


 */


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值