SDWebImage高清图内存溢出问题

我是一个搬运工,只会copy,转载转载转载:https://blog.csdn.net/benyoulai5/article/details/50462586

4.0.3版本时,可以改    

[SDImageCache sharedImageCache].config.shouldDecompressImages = NO;    [SDWebImageDownloader sharedDownloader].shouldDecompressImages = NO;

5.0.6版本时,以上属性不见了,看此链接https://blog.csdn.net/benyoulai5/article/details/50462586,

SDImageIOCoder.m 中

- (UIImage*)decodedImageWithData:(NSData*)dataoptions:(nullableSDImageCoderOptions*)options {

    if(!data) {

        returnnil;

    }

    CGFloatscale =1;

    NSNumber*scaleFactor = options[SDImageCoderDecodeScaleFactor];

    if(scaleFactor !=nil) {

        scale =MAX([scaleFactor doubleValue],1) ;

    }


    UIImage*image = [[UIImagealloc]initWithData:datascale:scale];

    if(data.length/1024>128) {

        image = [selfcompressImageWith:image];

    }

    image.sd_imageFormat = [NSData sd_imageFormatForImageData:data];

    returnimage;

}

-(UIImage *)compressImageWith:(UIImage *)image

{

    floatimageWidth = image.size.width;

    floatimageHeight = image.size.height;

    floatwidth =640;

    floatheight = image.size.height/(image.size.width/width);


    floatwidthScale = imageWidth /width;

    floatheightScale = imageHeight /height;


    // 创建一个bitmap的context

    // 并把它设置成为当前正在使用的context

    UIGraphicsBeginImageContext(CGSizeMake(width, height));

    if(widthScale > heightScale) {

        [imagedrawInRect:CGRectMake(0,0, imageWidth /heightScale , height)];

    }

    else{

        [imagedrawInRect:CGRectMake(0,0, width , imageHeight /widthScale)];

    }


    // 从当前context中创建一个改变大小后的图片

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    // 使当前的context出堆栈

    UIGraphicsEndImageContext();

    returnnewImage;

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容