65 lines
2.3 KiB
Mathematica
65 lines
2.3 KiB
Mathematica
|
|
//
|
||
|
|
// UIImage+Extender.m
|
||
|
|
// FashionApp
|
||
|
|
//
|
||
|
|
// Created by 1 on 2018/5/24.
|
||
|
|
// Copyright © 2018年 1. All rights reserved.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "UIImage+Extender.h"
|
||
|
|
|
||
|
|
@implementation UIImage (Extender)
|
||
|
|
+ (UIImage *)imageWithColor:(UIColor*)color size:(CGSize)size
|
||
|
|
{
|
||
|
|
CGRect rect =CGRectMake(0,0, size.width, size.height);
|
||
|
|
UIGraphicsBeginImageContext(rect.size);
|
||
|
|
CGContextRef context =UIGraphicsGetCurrentContext();
|
||
|
|
CGContextSetFillColorWithColor(context, [color CGColor]);
|
||
|
|
CGContextFillRect(context, rect);
|
||
|
|
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
|
||
|
|
UIGraphicsEndImageContext();
|
||
|
|
return image;
|
||
|
|
}
|
||
|
|
+ (UIImage *)createViewImage:(UIView *)shareView
|
||
|
|
{
|
||
|
|
UIGraphicsBeginImageContextWithOptions(shareView.bounds.size, NO, [UIScreen mainScreen].scale);
|
||
|
|
CGContextRef contextRef = UIGraphicsGetCurrentContext();
|
||
|
|
CGContextSetRGBFillColor(contextRef, 0.0, 0.0, 0.0, 0.0);
|
||
|
|
|
||
|
|
[shareView.layer renderInContext:contextRef];
|
||
|
|
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
|
||
|
|
UIGraphicsEndImageContext();
|
||
|
|
return image;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 二维码图片增加清晰度
|
||
|
|
+ (UIImage *)createUIImageFormCIImage:(CIImage *)image withSize:(CGSize)size {
|
||
|
|
|
||
|
|
CGRect extent = CGRectIntegral(image.extent);
|
||
|
|
CGFloat scale = MIN(size.width/CGRectGetWidth(extent), size.height/CGRectGetHeight(extent));
|
||
|
|
|
||
|
|
// 1.创建bitmap;
|
||
|
|
size_t width = CGRectGetWidth(extent) * scale;
|
||
|
|
size_t height = CGRectGetHeight(extent) * scale;
|
||
|
|
CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
|
||
|
|
CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
|
||
|
|
CIContext *context = [CIContext contextWithOptions:nil];
|
||
|
|
CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
|
||
|
|
CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
|
||
|
|
CGContextScaleCTM(bitmapRef, scale, scale);
|
||
|
|
CGContextDrawImage(bitmapRef, extent, bitmapImage);
|
||
|
|
|
||
|
|
// 2.保存bitmap到图片
|
||
|
|
CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
|
||
|
|
CGContextRelease(bitmapRef);
|
||
|
|
CGImageRelease(bitmapImage);
|
||
|
|
CGColorSpaceRelease(cs);
|
||
|
|
|
||
|
|
UIImage *qrcodeImage = [UIImage imageWithCGImage:scaledImage];
|
||
|
|
|
||
|
|
CGImageRelease(scaledImage);
|
||
|
|
|
||
|
|
return qrcodeImage;
|
||
|
|
}
|
||
|
|
@end
|