亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > 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!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲精品av在线| 97久久精品人人澡人人爽缅北| 国产日韩专区在线| 欧美精品九九久久| 国产精品成人av性教育| 中文字幕日韩有码| 国产va免费精品高清在线观看| 国产精品9999| 亚洲www视频| 中文字幕久热精品视频在线| 国产精品国产三级国产专播精品人| 国产精品一区二区久久久久| 中文字幕av一区二区三区谷原希美| 萌白酱国产一区二区| 91久久在线视频| 97超碰蝌蚪网人人做人人爽| 久久久国产精彩视频美女艺术照福利| 亚洲加勒比久久88色综合| 国产精品久久久久久久av电影| 国产精品情侣自拍| 日韩不卡中文字幕| 日韩中文字幕久久| 在线成人中文字幕| 精品福利一区二区| 91经典在线视频| 高潮白浆女日韩av免费看| 国产精品丝袜高跟| 欧美精品一区二区三区国产精品| 亚洲人线精品午夜| 国产精品揄拍一区二区| 国产香蕉97碰碰久久人人| 国产福利视频一区二区| 亚洲一区二区三区香蕉| 国产精品久久久亚洲| 黑人巨大精品欧美一区免费视频| 欧美精品在线观看| 高潮白浆女日韩av免费看| 国产丝袜精品视频| 亚洲影视中文字幕| 精品日韩中文字幕| 人妖精品videosex性欧美| 日韩免费在线播放| 亚洲一品av免费观看| 色av中文字幕一区| 日韩免费看的电影电视剧大全| 精品在线观看国产| 欧美一区二区三区免费视| 久久精品国产成人精品| 北条麻妃一区二区三区中文字幕| 午夜精品久久久久久久99热浪潮| 国产精品网站入口| 91精品成人久久| 国产精品久久久久久中文字| 欧美电影在线观看完整版| 中文字幕久热精品视频在线| 国产精品永久在线| 色综合男人天堂| 中文字幕一区电影| 国产精品成久久久久三级| 亚洲国产天堂久久综合| 国产日韩视频在线观看| 日韩欧美一区二区三区久久| 国产午夜精品美女视频明星a级| 欧美一级高清免费| 日韩精品在线私人| 国产一区玩具在线观看| 国产精品视频久久久久| 欧美日韩裸体免费视频| 国产精品久久久久久网站| 成人精品视频在线| 91中文字幕在线| 欧美超级乱淫片喷水| 亚洲午夜国产成人av电影男同| 国产精品网站大全| 欧美成人剧情片在线观看| 日韩在线免费视频观看| 亚洲影院色在线观看免费| 成人av资源在线播放| 亚洲丝袜av一区| 久久人人爽人人| 国产精品中文字幕久久久| 国产91久久婷婷一区二区| 中文字幕亚洲在线| 国产精品中文字幕在线观看| 日本高清久久天堂| 日韩视频在线免费观看| 国产精品对白刺激| 亚洲影院色在线观看免费| 成人国产精品久久久久久亚洲| 91精品久久久久久久久久入口| 中文字幕亚洲专区| 精品福利在线观看| 国产成人在线一区| 亚洲高清免费观看高清完整版| 91久久精品美女| 欧美亚洲在线视频| 欧美国产精品va在线观看| 欧美性高潮床叫视频| 在线观看国产精品日韩av| 一区二区三区四区在线观看视频| 久久人人爽人人爽人人片av高请| 91免费视频网站| 久久99亚洲精品| 成人激情视频在线播放| 国产精品视频一区国模私拍| 日韩一区av在线| 国模叶桐国产精品一区| 欧美一级成年大片在线观看| 992tv成人免费视频| 亚洲成人网久久久| 青青草原成人在线视频| 国产亚洲精品久久久久久777| 538国产精品视频一区二区| 在线a欧美视频| 欧美国产在线视频| 在线播放精品一区二区三区| 久久久之久亚州精品露出| 日本欧美中文字幕| 亚洲成人激情图| 在线日韩第一页| 亚洲а∨天堂久久精品9966| 国产成人精品免高潮费视频| 一区二区三区日韩在线| 国产亚洲人成网站在线观看| 精品国产一区二区在线| 影音先锋欧美在线资源| 久久精品视频在线观看| 亚洲自拍偷拍色图| 日韩视频免费看| 欧美一区第一页| 欧美精品激情在线观看| 日韩成人小视频| 日本精品免费一区二区三区| 国产mv久久久| 欧美极品少妇xxxxx| 国产成人涩涩涩视频在线观看| 欧美多人爱爱视频网站| 久久99热精品这里久久精品| 日韩中文第一页| 91亚洲国产精品| 亚洲a∨日韩av高清在线观看| 久久91超碰青草是什么| 91欧美精品午夜性色福利在线| 亚洲美女黄色片| 日韩欧美亚洲国产一区| 亚洲成av人片在线观看香蕉| 久久精品青青大伊人av| 亚洲影院高清在线| 欧美大片免费看| 欧美精品videossex性护士| 亚洲人成网站在线播| 日韩电影网在线| 9.1国产丝袜在线观看| 海角国产乱辈乱精品视频| 欧美日韩成人精品| 中文字幕一区二区精品| 国产日本欧美一区二区三区在线| 国产精品嫩草影院久久久| 一区二区三区回区在观看免费视频| 亚洲xxxx18| 亚洲成人性视频| 色综合男人天堂| 日韩高清有码在线| 国产日韩中文字幕|