我的
This commit is contained in:
@@ -31,7 +31,13 @@ typedef NS_ENUM(NSUInteger, GradientType) {
|
||||
+ (UIImage *)qx_convertViewToImageWith:(UIView *)view;
|
||||
|
||||
+ (UIImage *)qx_gradientColorImageFromColors:(NSArray*)colors gradientType:(GradientType)gradientType imgSize:(CGSize)imgSize;
|
||||
/**
|
||||
传入一张图片将图片改为灰色
|
||||
|
||||
@param inputImage 传入图片
|
||||
@return 生成的UIImage
|
||||
*/
|
||||
+ (UIImage *)qx_convertImageToGrayWithCoreImage:(UIImage *)inputImage;
|
||||
/**
|
||||
根据颜色,生成UIImage对象
|
||||
|
||||
|
||||
@@ -42,7 +42,24 @@
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
+ (UIImage *)qx_convertImageToGrayWithCoreImage:(UIImage *)inputImage {
|
||||
CIImage *ciImage = [[CIImage alloc] initWithImage:inputImage];
|
||||
|
||||
// 使用黑白滤镜
|
||||
CIFilter *grayFilter = [CIFilter filterWithName:@"CIColorControls"];
|
||||
[grayFilter setValue:ciImage forKey:kCIInputImageKey];
|
||||
[grayFilter setValue:@(0.0) forKey:kCIInputSaturationKey]; // 饱和度设为0即为灰色
|
||||
|
||||
CIImage *outputImage = [grayFilter valueForKey:kCIOutputImageKey];
|
||||
|
||||
CIContext *context = [CIContext contextWithOptions:nil];
|
||||
CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]];
|
||||
|
||||
UIImage *grayImage = [UIImage imageWithCGImage:cgImage];
|
||||
CGImageRelease(cgImage);
|
||||
|
||||
return grayImage;
|
||||
}
|
||||
+ (UIImage *)qx_gradientColorImageFromColors:(NSArray *)colors gradientType:(GradientType)gradientType imgSize:(CGSize)imgSize {
|
||||
NSMutableArray *ar = [NSMutableArray array];
|
||||
for (UIColor *c in colors) {
|
||||
|
||||
Reference in New Issue
Block a user