国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院

首頁 > 系統 > iOS > 正文

iOS7實現毛玻璃特效代碼

2020-02-19 15:57:47
字體:
來源:轉載
供稿:網友

原圖:

效果圖:

?實現:
首先需要導入Accelerate.framework。
然后把兩個文件加入到自己的項目中即可。
UIImage+ImageEffects.h

?


#import
@interfaceUIImage(ImageEffects)
-(UIImage*)applyLightEffect;
-(UIImage*)applyExtraLightEffect;
-(UIImage*)applyDarkEffect;
-(UIImage*)applyTintEffectWithColor:(UIColor*)tintColor;
-(UIImage*)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor*)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage*)maskImage;
@end

?

UIImage+ImageEffects.m

?


#import "UIImage+ImageEffects.h"
#import
#import
@implementationUIImage(ImageEffects)
-(UIImage*)applyLightEffect
{
UIColor*tintColor =[UIColor colorWithWhite:1.0 alpha:0.3];
return[self applyBlurWithRadius:30 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
}
-(UIImage*)applyExtraLightEffect
{
UIColor*tintColor =[UIColor colorWithWhite:0.97 alpha:0.82];
return[self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
}
-(UIImage*)applyDarkEffect
{
UIColor*tintColor =[UIColor colorWithWhite:0.11 alpha:0.73];
return[self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
}
-(UIImage*)applyTintEffectWithColor:(UIColor*)tintColor
{
constCGFloatEffectColorAlpha=0.6;
UIColor*effectColor = tintColor;
int componentCount =CGColorGetNumberOfComponents(tintColor.CGColor);
if(componentCount ==2){
CGFloat b;
if([tintColor getWhite:&b alpha:NULL]){
effectColor =[UIColor colorWithWhite:b alpha:EffectColorAlpha];
}
}
else{
CGFloat r, g, b;
if([tintColor getRed:&r green:&g blue:&b alpha:NULL]){
effectColor =[UIColor colorWithRed:r green:g blue:b alpha:EffectColorAlpha];
}
}
return[self applyBlurWithRadius:10 tintColor:effectColor saturationDeltaFactor:-1.0 maskImage:nil];
}
-(UIImage*)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor*)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage*)maskImage
{
// Check pre-conditions.
if(self.size.width NSLog(@"*** error: invalid size: (%.2f x %.2f). Both dimensions must be >= 1: %@",self.size.width,self.size.height,self);
returnnil;
}
if(!self.CGImage){
NSLog(@"*** error: image must be backed by a CGImage: %@",self);
returnnil;
}
if(maskImage &&!maskImage.CGImage){
NSLog(@"*** error: maskImage must be backed by a CGImage: %@", maskImage);
returnnil;
}
CGRect imageRect ={CGPointZero,self.size };
UIImage*effectImage =self;
BOOL hasBlur = blurRadius > __FLT_EPSILON__;
BOOL hasSaturationChange = fabs(saturationDeltaFactor -1.)> __FLT_EPSILON__;
if(hasBlur || hasSaturationChange){
UIGraphicsBeginImageContextWithOptions(self.size, NO,[[UIScreen mainScreen] scale]);
CGContextRef effectInContext =UIGraphicsGetCurrentContext();
CGContextScaleCTM(effectInContext,1.0,-1.0);
CGContextTranslateCTM(effectInContext,0,-self.size.height);
CGContextDrawImage(effectInContext, imageRect,self.CGImage);
vImage_Buffer effectInBuffer;
effectInBuffer.data =CGBitmapContextGetData(effectInContext);
effectInBuffer.width =CGBitmapContextGetWidth(effectInContext);
effectInBuffer.height =CGBitmapContextGetHeight(effectInContext);
effectInBuffer.rowBytes =CGBitmapContextGetBytesPerRow(effectInContext);
UIGraphicsBeginImageContextWithOptions(self.size, NO,[[UIScreen mainScreen] scale]);
CGContextRef effectOutContext =UIGraphicsGetCurrentContext();
vImage_Buffer effectOutBuffer;
effectOutBuffer.data =CGBitmapContextGetData(effectOutContext);
effectOutBuffer.width =CGBitmapContextGetWidth(effectOutContext);
effectOutBuffer.height =CGBitmapContextGetHeight(effectOutContext);
effectOutBuffer.rowBytes =CGBitmapContextGetBytesPerRow(effectOutContext);
if(hasBlur){
// A description of how to compute the box kernel width from the Gaussian
// radius (aka standard deviation) appears in the SVG spec:
// http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
//
// For larger values of 's' (s >= 2.0), an approximation can be used: Three
// successive box-blurs build a piece-wise quadratic convolution kernel, which
// approximates the Gaussian kernel to within roughly 3%.
//
// let d = floor(s * 3*sqrt(2*pi)/4 + 0.5)
//
// ... if d is odd, use three box-blurs of size 'd', centered on the output pixel.
//
CGFloat inputRadius = blurRadius *[[UIScreen mainScreen] scale];
NSUInteger radius = floor(inputRadius *3.* sqrt(2* M_PI)/4+0.5);
if(radius %2!=1){
radius +=1;// force radius to be odd so that the three box-blur methodology works.
}
vImageBoxConvolve_ARGB8888(&effectInBuffer,&effectOutBuffer, NULL,0,0, radius, radius,0, kvImageEdgeExtend);
vImageBoxConvolve_ARGB8888(&effectOutBuffer,&effectInBuffer, NULL,0,0, radius, radius,0, kvImageEdgeExtend);
vImageBoxConvolve_ARGB8888(&effectInBuffer,&effectOutBuffer, NULL,0,0, radius, radius,0, kvImageEdgeExtend);
}
BOOL effectImageBuffersAreSwapped = NO;
if(hasSaturationChange){
CGFloat s = saturationDeltaFactor;
CGFloat floatingPointSaturationMatrix[]={
0.0722+0.9278* s,0.0722-0.0722* s,0.0722-0.0722* s,0,
0.7152-0.7152* s,0.7152+0.2848* s,0.7152-0.7152* s,0,
0.2126-0.2126* s,0.2126-0.2126* s,0.2126+0.7873* s,0,
0,0,0,1,
};
constint32_t divisor =256;
NSUInteger matrixSize =sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
int16_t saturationMatrix[matrixSize];
for(NSUInteger i =0; i saturationMatrix[i]=(int16_t)roundf(floatingPointSaturationMatrix[i]* divisor);
}
if(hasBlur){
vImageMatrixMultiply_ARGB8888(&effectOutBuffer,&effectInBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
effectImageBuffersAreSwapped = YES;
}
else{
vImageMatrixMultiply_ARGB8888(&effectInBuffer,&effectOutBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
}
}
if(!effectImageBuffersAreSwapped)
effectImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if(effectImageBuffersAreSwapped)
effectImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
// Set up output context.
UIGraphicsBeginImageContextWithOptions(self.size, NO,[[UIScreen mainScreen] scale]);
CGContextRef outputContext =UIGraphicsGetCurrentContext();
CGContextScaleCTM(outputContext,1.0,-1.0);
CGContextTranslateCTM(outputContext,0,-self.size.height);
// Draw base image.
CGContextDrawImage(outputContext, imageRect,self.CGImage);
// Draw effect image.
if(hasBlur){
CGContextSaveGState(outputContext);
if(maskImage){
CGContextClipToMask(outputContext, imageRect, maskImage.CGImage);
}
CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
CGContextRestoreGState(outputContext);
}
// Add in color tint.
if(tintColor){
CGContextSaveGState(outputContext);
CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
CGContextFillRect(outputContext, imageRect);
CGContextRestoreGState(outputContext);
}
// Output image is ready.
UIImage*outputImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outputImage;
}
@end

?

調用:
?


UIImageView*me =[[UIImageView alloc] initWithFrame:CGRectMake(10,480,614,381)];
[me setImage:[[UIImage imageNamed:@"me.png"] applyBlurWithRadius:5 tintColor:[UIColor colorWithWhite:1 alpha:0.2] saturationDeltaFactor:1.8 maskImage:nil]];
[self.view addSubview:me];

?

ok!So easy!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院
国产中文字幕av| www在线视频观看| 国产天堂资源| 国产福利在线播放| 中文av资源在线| 在线观看av资源网| 在线天堂视频| 超碰91在线| 国产区视频在线播放| 国产黄色片在线播放| 九九热视频免费在线观看| 尤物网在线观看| 91网页在线观看| 日本电影在线观看| 国产色在线观看| 天堂中文资源在线| 欧美日韩在线中文字幕| 精品视频vs精品视频| 国产激情三区| 奇米影视狠狠狠| 成网站在线观看人免费| 免费网站看黄yyy222| 中文字幕日本在线| wwww亚洲| 四虎免费视频| 精品美女调教视频| 99热在线观看免费| 国产中文伊人| 日本高清不卡中文字幕| 97视频网站| 国产成人精品综合网站| 国产女人在线观看| 超碰国产在线| 超碰在线网址| 激情小说 在线视频| 超碰在线观看免费版| 樱花草在线观看www| 国产成人亚洲欧美电影| 国产精品视频福利一区二区| 久久这里精品| 国产免费av在线| 日本黄色免费网址| 一本大道久久精品| 尤物在线精品视频| 亚洲图区综合| 亚洲第一成年免费网站| 亚洲综合在线不卡| 在线天堂av| baoyu777.永久免费视频| 国产福利一区二区在线精品| 国产香蕉尹人视频在线| 丁香在线视频| 国产天堂素人系列在线视频| 国产黄色在线播放| 香蕉视频免费在线播放| www.操操操.com| 超碰免费97在线观看| 五月婷婷在线观看| 国产高清免费av在线| 四虎国产精品永久地址998| jlzzjlzz欧美大全| 国产一级二级三级在线观看| 精品视频一二区| 色欧美在线观看| 福利在线视频导航| 精品无人乱码| 一本大道香蕉8中文在线视频| a视频免费看| 国产精品外围在线观看| 国产wwww| 青青青手机在线视频观看| 黄色毛片在线| 国产区在线看| 四虎www视频| 最近最好的中文字幕2019免费 | 国产啊啊啊视频在线观看| av在线播放av| 中文字幕日本三级| 美女av在线播放| 国产偷窥老熟盗摄视频| 亚洲精品aaaa| 中文字幕4区| 国产区在线观看| 二区中文字幕| 免费在线你懂的| 一本久久精品| 精品国内自产拍在线视频| 国产美女视频一区二区二三区| 在线色视频观看| 中文岛国精品亚洲一区| 2019天天操夜夜操| 最新中文字幕av专区| 国产在线更新| 国产综合视频一区二区三区免费| 中文乱码字幕高清在线观看| 国产丝袜自拍| 97操碰视频| 99爱视频在线观看| 午夜羞羞小视频在线观看| 国产a国产a国产a| 国产福利热线视频| 2019中文字幕视频| 伊人资源视频在线| 亚洲高清在线免费| wwww在线观看| 久热国产视频| 91福利在线免费| 中文字幕在线免费| 国产成人亚洲欧美电影| 国产私人影院| 亚洲日本一区二区三区在线观看| 在线观看免费观看在线91| 亚洲xxxxxx| 国产在线超碰| 精品福利视频导航大全| 亚洲久草视频| 福利在线国产| 91亚洲欧美| 日本成人网址| 国产午夜视频| 热99re久久精品这里都是免费| 久久久久久77777| 国产区视频在线观看| 亚洲精品自产拍在线观看| 亚洲夜夜综合| 中文字幕成人乱码在线电影| 精品麻豆国产| 丁香视频五月| 亚洲欧美一区二区三区在线播放| 欧美日韩**字幕一区| 中文字幕麻豆| 欧美激情福利视频在线观看免费| 最近免费中文字幕大全免费第三页| 2020亚洲男人天堂| 快射av在线播放一区| 精品极品三级久久久久| 99热在线免费播放| 亚洲精品一区中文字幕电影| 午夜av在线免费观看| 国产成人福利| 中文字幕在线视频网| 男人天堂99| eeuss影院www在线观看| 精品一二三四| 国产视频精选在线| 导航福利在线| 高清视频一区二区三区四区| xxx国产精品| jlzzjlzz欧美大全| 在线亚洲不卡| 一区二区三区免费视频网站| 国产偷窥老熟盗摄视频| 91超碰在线免费| 国产精品自拍在线观看| 中文字幕av在线播放| 国产成人综合美国十次| 国产精品冒白浆免费视频 | 国产在线高潮| 另类高清dbsm日本tvav| 日本三级在线视频| 精品国产一区二区三区久久久狼牙| √天堂资源地址在线官网| 福利视频在线导航| 国产精品午夜久久久久久| 国产免费电影网站入口| 国产免费av网站| 激情五月色综合亚洲小说| 男人操女人免费网站| 免费在线黄色av| 国产麻豆麻豆| 国产区在线观看| 99reav| 亚洲成人国产综合| 国产中文字幕在线| 国产一级免费看| 91免费日韩| www.久草.com| 最新国产在线精品91尤物| 国产人成在线观看| 日本h视频在线观看| 天堂在线免费观看| 在线观看电影av| 欧美96在线| 国产精品视频一区二区图片| 在线中文av| 黄色国产网站在线播放| 国产福利视频在线观看| 亚洲精品在线播放视频| 国产自产视频| 亚洲欧美综合乱码精品成人网| 成人欧美亚洲| av麻豆国产| 国产精品视频h| 青青九九免费视频在线| 国产福利一区二区在线精品| 免费网站看黄yyy222| 91麻豆福利| 人人在线视频| 在线国产一级| 国产福利在线播放|