私はUIImage *image = [UIImage imageWithData: data]
を使用していますが、4 times.Original data.length = 100キロバイトによる画像のサイズが大きいが、これ画像は今400 KB.Youが完了すると言うかもしれないより多くを持っています私は圧縮後に以下のメソッドを使用していますdata.length = 200 KB。 NSDataのUIImageに品質
次
は私の方法である
// spend is size (KB)
- (NSData *)compressionImageData:(NSData *)data spend:(CGFloat)spend {
if (data.length < spend) {
return data; //no compression
}
UIImage *sourceImg = [UIImage imageWithData:data];
CGFloat compression = 0.9f;
CGFloat maxCompression = 0.1f;
NSData *imageData = UIImageJPEGRepresentation(sourceImg, compression);
while ([imageData length] > spend && compression > maxCompression) {
compression -= 0.1;
imageData = UIImageJPEGRepresentation(sourceImg, compression);
}
return imageData;
}
は、画像法をダウンロードした圧縮方式:
- (void)loadPosterImage:(NSString *)imgURL {
weakSelf();
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:imgURL]
options:SDWebImageDownloaderLowPriority
progress:^(NSInteger receivedSize, NSInteger expectedSize) {}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
strongSelf();
// image is through [UIImage imageWithData: data]
self.posterImage = image;
self.posterData = data;
}];
}
画像サイズこれは、これは画像ある画像
のdata.lengthある以上500キロバイト
data.lenght = 100キロバイト
を有します画像の
は、画像サイズやデータに直接データを配置する方法はあります.length size – xsflyer
あなたは何を達成しようとしていますか? – Adeel
あなたは何をしたいですか? – KKRocks