美文网首页
图片压缩

图片压缩

作者: wylei | 来源:发表于2016-09-22 20:32 被阅读17次

    压缩 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

    相关文章

      网友评论

          本文标题:图片压缩

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