在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:seanooi/iOS-WebP开源软件地址:https://github.com/seanooi/iOS-WebP开源编程语言:Objective-C 97.0%开源软件介绍:iOS-WebPMost apps nowadays enhance user experience with the use of images, and one of the issues I've noticed with that is the amount of time it takes to load an image. (Not everyone has the luxury of a fast connection) Google's WebP image format offers better compression compared to PNG or JPEG, allowing apps to send/retrieve images with smaller file sizes, reducing request times and hopefully provide a better user experience. Getting StartedThe CocoaPods Waypod 'iOS-WebP', '0.5' UsageDon't forget to + (void)imageToWebP:(UIImage *)image quality:(CGFloat)quality alpha:(CGFloat)alpha preset:(WebPPreset)preset
completionBlock:(void (^)(NSData *result))completionBlock
failureBlock:(void (^)(NSError *error))failureBlock;
+ (void)imageWithWebP:(NSString *)filePath
completionBlock:(void (^)(UIImage *result))completionBlock
failureBlock:(void (^)(NSError *error))failureBlock;
- (UIImage *)imageByApplyingAlpha:(CGFloat)alpha; Encoding and decoding of images are done in the background thread and results returned in the completion block on the main thread so as not to lock the main thread, allowing the UI to be updated as needed. Converting To WebP// quality value is [0, 100]
// alpha value is [0, 1]
[UIImage imageToWebP:[UIImage imageNamed:@"demo.jpg"] quality:quality alpha:alpha preset:WEBP_PRESET_DEFAULT completionBlock:^(NSData *result) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *webPPath = [paths[0] stringByAppendingPathComponent:@"image.webp"];
if (![result writeToFile:webPPath atomically:YES]) {
NSLog(@"Failed to save file");
}
} failureBlock:^(NSError *error) {
NSLog(@"%@", error.localizedDescription);
}];
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论