我是一个搬运工,只会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;
}