iOS 图片压缩

2020-06-09  本文已影响0人  Zhen斌iOS

图片压缩核心代码

-(UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize {
    // Create a graphics image context 
    UIGraphicsBeginImageContext(newSize);
    // Tell the old image to draw in this new context, with the desired newsize 
    [image drawInRect: CGRectMake(0,0,newSize.width,newSize.height)]; 
    // Get the new image from the context 
    UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();
    // Endthecontext 
    UIGraphicsEndImageContext();
    // Return the new image.
    return newImage;
}

图片压缩调用

UIImage*yourImage=[self imageWithImageSimple:image scaledToSize: CGSizeMake(210.0,210.0)];

希望对你有帮助!

上一篇 下一篇

猜你喜欢

热点阅读