SDWebImage加载多个网络高清图片内存崩溃 Crash
生活随笔
收集整理的這篇文章主要介紹了
SDWebImage加载多个网络高清图片内存崩溃 Crash
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?// SDWebImage? -> ?Core? -> SDImageIOCoder.m- (UIImage *)decodedImageWithData:(NSData *)data options:(nullable SDImageCoderOptions *)options {if (!data) {return nil;}CGFloat scale = 1;NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];if (scaleFactor != nil) {scale = MAX([scaleFactor doubleValue], 1) ;}UIImage *image = [[UIImage alloc] initWithData:data scale:scale];image.sd_imageFormat = [NSData sd_imageFormatForImageData:data];// 大于50k就對圖片進行壓縮if (data.length/1024 > 50) {image = [self compressImageWith:image];}return image;
}// add by jack on 20190814
-(UIImage *)compressImageWith:(UIImage *)image
{float imageWidth = image.size.width;float imageHeight = image.size.height;float width = 200;//640float height = image.size.height/(image.size.width/width);float widthScale = imageWidth /width;float heightScale = imageHeight /height;// 創建一個bitmap的context// 并把它設置成為當前正在使用的contextUIGraphicsBeginImageContext(CGSizeMake(width, height));if (widthScale > heightScale) {[image drawInRect:CGRectMake(0, 0, imageWidth /heightScale , height)];}else {[image drawInRect:CGRectMake(0, 0, width , imageHeight /widthScale)];}// 從當前context中創建一個改變大小后的圖片UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();// 使當前的context出堆棧UIGraphicsEndImageContext();return newImage;
}
?
轉載于:https://my.oschina.net/jack088/blog/3092991
總結
以上是生活随笔為你收集整理的SDWebImage加载多个网络高清图片内存崩溃 Crash的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【金融财经】金融市场一周简报(2017-
- 下一篇: 1045 Favorite Color