@binbins
2017-06-23T11:03:22.000000Z
字数 1176
阅读 274
bug SDWebImage
+(UIImage *)compressImageWith:(UIImage *)image{float imageWidth = image.size.width;float imageHeight = image.size.height;float width = 640;float 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;}
image = [[UIImage alloc] initWithData:data];if (data.length/1024 > 128) {image = [self compressImageWith:image];}
UIImage *image = [UIImage sd_imageWithData:self.imageData];//将等比压缩过的image在赋在转成data赋给self.imageDataNSData *data = UIImageJPEGRepresentation(image, 1);self.imageData = [NSMutableData dataWithData:data];
[[SDImageCache sharedImageCache] setValue:nil forKey:@"memCache"];