您好,欢迎来到知库网。
搜索
您的当前位置:首页iOS 写入2倍和3倍图片到沙盒

iOS 写入2倍和3倍图片到沙盒

来源:知库网
/**< 写入2倍和3倍图片到沙盒 */
- (NSString *)configTabbarItemImageWithUrl:(NSString *)imageUrl {
    NSArray *stringArray = [imageUrl componentsSeparatedByString:@"/"];
    NSString *imageName = stringArray.lastObject;
    NSArray *tempArray = [imageName componentsSeparatedByString:@"."];
    NSString *newImageName = tempArray.firstObject;
    NSString *doubleImageName = nil;
    NSString *tripleImageName = nil;
    if ([newImageName haveValueString]) {
        doubleImageName = [NSString stringWithFormat:@"%@@2x.png",newImageName];
        tripleImageName = [NSString stringWithFormat:@"%@@3x.png",newImageName];
    }
    UIImage *loadImage = [UIImage sd_imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]];
    NSArray *pathArray = (NSArray *)NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
    NSString *path = pathArray.firstObject;
    NSString *doublefilePath = [path stringByAppendingPathComponent:doubleImageName];
    NSString *triplefilePath = [path stringByAppendingPathComponent:tripleImageName];
    if ([UIImagePNGRepresentation(loadImage) writeToFile:doublefilePath atomically:YES]) {
        XLog(@"写入2倍图片成功")
    }
    if ([UIImagePNGRepresentation(loadImage) writeToFile:triplefilePath atomically:YES]) {
        XLog(@"写入3倍图片成功")
    }
    return [NSString stringWithFormat:@"%@/%@.png",path,newImageName];
}

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务