Google produced high-definition, small volume of image format, the following is how to use under iOS
Add header File
#import "Uiimage+webp.h"
#import "ViewController.h" #import "Uiimage+webp.h" @interface Viewcontroller () @property (nonatomic, Strong) Uiimageview *webpimageview; @property (nonatomic, strong) UILabel *webplabel1; @end @implementation viewcontroller-( void) Viewdidload {[Super viewdidload]; Additional setup after loading the view, typically from a nib. NSString *normalimg = [[NSBundle mainbundle] pathforresource:@ "changmen1" oftype:@ "PNG"]; uint64_t fileSize = [[[Nsfilemanager Defaultmanager] attributesofitematpath:normalimg Error:nil] fileSize]; UIImage *demoimage = [UIImage imagenamed:@ "Changmen1.png"]; Uiimageview *pngview = [[Uiimageview alloc] initwithimage:demoimage]; Pngview.frame = CGRectMake (0, 0, demoImage.size.width, demoImage.size.height); [Self.view Addsubview:pngview]; UILabel *pnglabel = [[UILabel alloc] Initwithframe:cgrectmake (0, Cgrectgetmaxy (pngview.frame) + 5,300, 10)]; Pnglabel.text = [NSString stringwithformat:@ "%@ format File size:%.2f KB ", [[Normalimg pathextension] uppercasestring], (double) filesize/1024]; [Pnglabel Setfont:[uifont Systemfontofsize:12]; [Self.view Addsubview:pnglabel]; _webpimageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0, Cgrectgetmaxy (pngview.frame) + 20, DemoImage.size.width, DemoImage.size.height)]; [Self.view Addsubview:_webpimageview]; _webplabel1 = [[UILabel alloc] Initwithframe:cgrectmake (0, Cgrectgetmaxy (_webpimageview.frame) + 5,300, 10)]; [_webplabel1 Setfont:[uifont Systemfontofsize:12]; [Self.view Addsubview:_webplabel1]; [UIImage imagetowebp:demoimage quality:75.0 alpha:1.0 preset:webp_preset_photo completionblock:^ (NSData *result) {[Self displayimagewithdata:result]; } failureblock:^ (Nserror *error) {}]; }-(void) Displayimagewithdata: (NSData *) webpdata{Nsarray *paths = Nssearchpathfordirectoriesindomains ( NSDocumentDirectory, Nsuserdomainmask, YES); NSString *webppath = [pathS[0] stringbyappendingpathcomponent:@ "IMAGE.WEBP"]; if ([Webpdata writetofile:webppath Atomically:yes]) {[UIImage imagewithwebp:webppath completionblock:^ (UIImage *re Sult) {uint64_t fileSize = [[[Nsfilemanager Defaultmanager] Attributesofitematpath:webppath Error:nil] FileSiz E]; _webplabel1.text = [NSString stringwithformat:@ "%@ format File size:%.2f KB", [[Webppath pathextension] uppercasestring] , (double) filesize/1024]; [_webpimageview Setimage:result]; } failureblock:^ (Nserror *error) {}]; } }
Effect:
Original address: http://blog.csdn.net/qqmcy/article/details/43085197
Code Download: http://download.csdn.net/detail/qqmcy/8392601
IOS WEBP Picture Format