图片压缩

压缩 UIImage
UIImage+Scale.h
@interface UIImage (Scale)
//等比率缩放

  • (UIImage *)scaleImageToScale:(float)scale;

//自定长宽

  • (UIImage*)scaleImageToSize:(CGSize)size;
    @end

UIImage+Scale.m

import "UIImage+Scale.h"

@implementation UIImage (Scale)

//等比率缩放

  • (UIImage *)scaleImageToScale:(float)scale
    {
    UIGraphicsBeginImageContext(CGSizeMake(self.size.width * scale, self.size.height * scale)); [self drawInRect:CGRectMake(0, 0, self.size.width * scale, self.size.height * scale)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
    return scaledImage;
    }
    //自定长宽
  • (UIImage)scaleImageToSize:(CGSize)size{
    UIGraphicsBeginImageContext(size);
    [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage
    scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
    return scaledImage;
    }

@end

你可能感兴趣的:(图片压缩)