IOS8 generating two-dimensional code and barcode

Source: Internet
Author: User

IOS8 generating two-dimensional code and barcode

:

Source:

////VIEWCONTROLLER.M//Codecreator////Created by youxianming on 15/3/16.//Copyright (c) 2015 youxianming. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller () @property (nonatomic, strong) Uiimageview*ImageView;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.imageview= [[Uiimageview alloc] Initwithframe:cgrectmake (0,0, $, $)]; Self.imageView.center=Self.view.center;            [Self.view AddSubview:self.imageView]; [Self generatecode];}-(UIImage *) Resizeimage: (UIImage *) Image withquality: (cginterpolationquality) Quality rate: (cgfloat) rate {UIImage *resized =Nil; CGFloat width= Image.size.width *Rate ; CGFloat height= Image.size.height *Rate ;    Uigraphicsbeginimagecontext (Cgsizemake (width, height)); Cgcontextref Context=Uigraphicsgetcurrentcontext ();    Cgcontextsetinterpolationquality (context, quality); [Image Drawinrect:cgrectmake (0,0, width, height)]; Resized=Uigraphicsgetimagefromcurrentimagecontext ();        Uigraphicsendimagecontext (); returnresized;}- (void) Generatecode {//@ "Cicode128barcodegenerator" Barcode//@ "Ciazteccodegenerator" two-dimensional codeNSString *filtername =@"Cicode128barcodegenerator"; Cifilter*filter =[Cifilter Filterwithname:filtername];        [Filter SetDefaults]; NSData*data = [@"youxianming"datausingencoding:nsutf8stringencoding]; [Filter setvalue:data Forkey:@"InputMessage"]; Ciimage*outputimage =[Filter outputimage]; Cicontext*context =[Cicontext Contextwithoptions:nil]; Cgimageref Cgimage=[Context Createcgimage:outputimage fromrect:[outputimage extent]; UIImage*image =[UIImage imagewithcgimage:cgimage scale:1.        Orientation:uiimageorientationup]; //Resize without interpolatingCGFloat scalerate = self.imageView.frame.size.width/Image.size.width; UIImage*resized =[Self resizeimage:image withquality:kcginterpolationnone        Rate:scalerate]; Self.imageView.image=resized; Cgimagerelease (cgimage);}@end

IOS8 generating two-dimensional code and barcode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.