两折卖----返利app-----返利圈

CIImage+YHExtend.m 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // CIImage+YHExtend.m
  3. // YouHuiProject
  4. //
  5. // Created by jcymac on 2018/5/19.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "CIImage+YHExtend.h"
  9. @implementation CIImage (YHExtend)
  10. /**
  11. * 根据CIImage生成指定大小的UIImage
  12. *
  13. * @param size 图片宽度
  14. */
  15. - (UIImage *)createNonInterpolatedUIImagewithSize:(CGFloat) size
  16. {
  17. CGRect extent = CGRectIntegral(self.extent);
  18. CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
  19. // 1.创建bitmap;
  20. size_t width = CGRectGetWidth(extent) * scale;
  21. size_t height = CGRectGetHeight(extent) * scale;
  22. CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
  23. CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
  24. CIContext *context = [CIContext contextWithOptions:nil];
  25. CGImageRef bitmapImage = [context createCGImage:self fromRect:extent];
  26. CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
  27. CGContextScaleCTM(bitmapRef, scale, scale);
  28. CGContextDrawImage(bitmapRef, extent, bitmapImage);
  29. // 2.保存bitmap到图片
  30. CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
  31. CGContextRelease(bitmapRef);
  32. CGImageRelease(bitmapImage);
  33. return [UIImage imageWithCGImage:scaledImage];
  34. }
  35. @end