美文网首页
iOS 图片压缩

iOS 图片压缩

作者: Zhen斌iOS | 来源:发表于2020-06-09 11:20 被阅读0次

图片压缩核心代码

-(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)];

希望对你有帮助!

相关文章

网友评论

      本文标题:iOS 图片压缩

      本文链接:https://www.haomeiwen.com/subject/ytlstktx.html