2017-07-06 111 views
1

我想減小UIImage並使用下面的方法。縮小UIImage但返回更大的內存大小?

- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size { 
    UIGraphicsBeginImageContext(size); 
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; 
    UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return destImage; 
} 

它返回正確的尺寸,但具有比原始圖像更大的圖像尺寸(內存)。如何優化方法?

+0

確保您使用相同的比例。此外,圖像將以不同的方式呈現。 – Sulthan

+1

當你說「大於原始大小」時,你的意思是否大於'.png'文件(或其它什麼)? – Fogmeister

回答

-1

您可以壓縮您的圖像,其規模將decrese

NSData* data = UIImageJPEGRepresentation(image, 0.8);