探索毛玻璃效果的神奇世界:创意视觉体验全解析

更新:11-17 名人轶事 我要投稿 纠错 投诉

iOS8

在iOS8中,Apple提供了一种新的实现方法UIBlurEffect。苹果也建议开发者使用这种方法,但如果你的项目需要支持iOS7,就不要考虑这种方法。

使用第三方

图像模糊的分类

先来看看原图

Snip20170612_10.png 使用三种方法进行高斯模糊处理。

直接上传代码

- (void)viewDidLoad {

[超级viewDidLoad];

UIImageView *imageView=[[UIImageView alloc] initWithFrame:self.view.bounds];

imageView.image=[UIImage imageNamed:@"flower.jpg"];

[self.view addSubview:imageView];

//iOS7

/*

typedef NS_ENUM(NSInteger, UIBarStyle) {

UIBarStyle默认=0,

UIBarStyleBlack=1,

UIBarStyleBlackOpaque=1, //已弃用。使用UIBarStyleBlack

UIBarStyleBlackTranslucent=2, //已弃用。使用UIBarStyleBlack 并将半透明属性设置为YES

}

*/

UIToolbar *toolbar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(self.view.frame), 200)];

工具栏.barStyle=UIBarStyleDefault;

[self.view addSubview:toolbar];

//iOS8

/*

typedef NS_ENUM(NSInteger, UIBlurEffectStyle) {

UIBlurEffectStyleExtraLight,

UIBlurEffectStyleLight,

UIBlurEffectStyleDark,

UIBlurEffectStyleExtraDark __TVOS_AVAILABLE(10_0) __IOS_PROHIBITED __WATCHOS_PROHIBITED,

UIBlurEffectStyleRegular NS_ENUM_AVAILABLE_IOS(10_0), //适应用户界面风格

UIBlurEffectStyleProminent NS_ENUM_AVAILABLE_IOS(10_0), //适应用户界面风格

}

*/

UIBlurEffect *blurEffect=[UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight];

UIVisualEffectView *effectView=[[UIVisualEffectView alloc] initWithEffect:blurEffect];

effectView.frame=CGRectMake(0, CGRectGetMaxY(self.view.frame) - 500, CGRectGetMaxX(self.view.frame), 200);

[self.view addSubview:effectView];

//第三者

UIImage *image=[[UIImage imageNamed:@"bottom"] applyLightEffect];

UIImageView *imageView2=[[UIImageView 分配] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.view.frame) - 200, CGRectGetMaxX(self.view.frame), 200)];

imageView2.image=图像;

[self.view addSubview:imageView2];

}以上效果图(这里以光线为例)

截图20170612_11.png

还有其他几种枚举效果,有兴趣的话可以尝试一下。

附上第三方

/*

文件: UIImage+ImageEffects.m

Abstract: 这是UIImage 的一个类别,添加了对图像应用模糊和色调效果的方法。这是您需要查看的代码,以了解如何使用vImage 有效地计算模糊。

版本: 1.0

免责声明: 重要: 此Apple 软件由Apple 向您提供

Inc.(“Apple”)考虑到您同意以下内容

条款以及您的使用、安装、修改或重新分发

使用此Apple 软件即表示接受这些条款。如果你这样做

不同意这些条款,请不要使用、安装、修改或

重新分发此Apple 软件。

考虑到您同意遵守以下条款,并且

根据这些条款,Apple 授予您个人的、非排他性的

许可证,根据Apple 的原始Apple 软件版权(

“Apple 软件”),使用、复制、修改和重新分发Apple

软件,无论是否经过修改,均采用源代码和/或二进制形式;

前提是,如果您重新分发整个Apple 软件并且

未经修改,您必须保留本通知和以下内容

Apple 软件的所有此类重新分发中的文本和免责声明。

Apple Inc. 的名称、商标、服务标记或徽标均不得

用于认可或推广源自Apple 软件的产品

未经Apple 事先书面许可。除非作为

本通知中明确规定,没有其他权利或许可、明示或

Apple 在此授予暗示,包括但不限于任何

您的衍生作品或其他人可能侵犯的专利权

可能包含Apple 软件的作品。

Apple 软件由Apple 按“原样”提供。苹果

不作任何明示或暗示的保证,包括但不限于

非侵权、适销性和适用性的默示保证

出于特定目的,关于Apple 软件或其使用和

单独操作或与您的产品结合使用。

在任何情况下,Apple 均不对任何特殊、间接、附带的情况承担责任

或间接损害(包括但不限于采购

替代商品或服务;使用、数据或利润的损失;或商业

因使用、复制、

无论何种原因造成的Apple 软件修改和/或分发

以及是否根据合同理论、侵权行为(包括疏忽),

严格责任或其他情况,即使Apple 已被告知

发生此类损坏的可能性。

版权所有(C) 2013 Apple Inc. 保留所有权利。

版权所有 2013 Apple Inc. 保留所有权利。

WWDC 2013 许可证

注: 此Apple 软件由Apple 作为WWDC 2013 的一部分提供

会议。请参阅适用的WWDC 2013 会议了解更多信息

信息。

重要信息: 此Apple 软件由Apple Inc. 向您提供。

(“Apple”)考虑到您同意以下条款,并且

您对本Apple 的使用、安装、修改或重新分发

软件即表示接受这些条款。如果您不同意

这些条款,请不要使用、安装、修改或重新分发

苹果软件。

考虑到您同意遵守以下条款,并且

根据这些条款,Apple 授予您非独占许可,

Apple 对此原始Apple 软件的版权(“Apple

软件”),使用、复制、修改和重新分发Apple

软件,无论是否经过修改,均采用源代码和/或二进制形式;

前提是如果您重新分发整个Apple 软件并且

未经修改,您必须保留本通知和以下内容

Apple 软件的所有此类重新分发中的文本和免责声明。

Apple Inc. 的名称、商标、服务标记或徽标均不得

用于认可或推广源自Apple 软件的产品

未经Apple 事先书面许可。除非作为

本通知中明确规定,没有其他权利或许可、明示或

Apple 在此授予暗示,包括但不限于任何

您的衍生作品或其他人可能侵犯的专利权

可能包含Apple 软件的作品。

Apple 软件由Apple 按“原样”提供。苹果制造

不提供任何明示或暗示的保证,包括但不限于

非侵权、适销性和适用性的默示保证

特定目的,关于Apple 软件或其使用和

单独操作或与您的产品结合使用。

在任何情况下,Apple 均不对任何特殊、间接、附带的情况承担责任

或间接损害(包括但不限于采购

替代商品或服务;使用、数据或利润的损失;或商业

因使用、复制、

无论何种原因造成的Apple 软件修改和/或分发

以及是否根据合同理论、侵权行为(包括疏忽),

严格责任或其他情况,即使Apple 已被告知

发生此类损坏的可能性。

EA1002

2013年5月3日

*/

#import "UIImage+ImageEffects.h"

@导入加速;

#import@implementation UIImage(图像效果)

- (UIImage *)应用光效

{

UIColor *tintColor=[UIColor colorWithWhite:1.0 alpha:0.3];

返回[self applyBlurWithRadius:30 TintColor:tintColor SaturationDeltaFactor:1.8 maskImage:nil];

}

- (UIImage *)应用额外光效

{

UIColor *tintColor=[UIColor colorWithWhite:0.97 alpha:0.82];

返回[self applyBlurWithRadius:20 TintColor:tintColor SaturationDeltaFactor:1.8 maskImage:nil];

}

- (UIImage *)应用深色效果

{

UIColor *tintColor=[UIColor colorWithWhite:0.11 alpha:0.73];

返回[self applyBlurWithRadius:20 TintColor:tintColor SaturationDeltaFactor:1.8 maskImage:nil];

}

- (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor

{

常量CGFloat EffectColorAlpha=0.6;

UIColor *effectColor=色调颜色;

int componentCount=CGColorGetNumberOfComponents(tintColor.CGColor);

if (组件计数==2) {

CGFloat b;

if ([tintColor getWhite:b alpha:NULL]) {

effectColor=[UIColor colorWithWhite:b alpha:EffectColorAlpha];

}

}

别的{

CGFloat r、g、b;

if ([tintColor getRed:r green:g blue:b alpha:NULL]) {

effectColor=[UIColor colorWithRed:r green:g blue:b alpha:EffectColorAlpha];

}

}

返回[self applyBlurWithRadius:10 TintColor:effectColor SaturationDeltaFactor:-1.0 maskImage:nil];

}

- (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius twinColor:(UIColor *)tint颜色饱和度DeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage

{

//检查先决条件。

if (self.size.width 1 || self.size.height 1) {

NSLog(@"*** error: 无效的size: (%.2f x %.2f)。两个尺寸必须=1: %@", self.size.width, self.size.height, self);

返回零;

}

if (!self.CGImage) {

NSLog (@"*** error: 图像必须由CGImage: %@", self 支持);

返回零;

}

if (maskImage!maskImage.CGImage) {

NSLog (@"*** error: maskImage 必须由CGImage: %@", maskImage 支持);

返回零;

}

CGRect imageRect={ CGPointZero, self.size };

UIImage *effectImage=self;

BOOL hasBlur=blurRadius __FLT_EPSILON__;

BOOL hasSaturationChange=fabs(saturationDeltaFactor - 1.) __FLT_EPSILON__;

如果(hasBlur || hasSaturationChange){

UIGraphicsBeginImageContextWithOptions(self.size, NO, [[UIScreen mainScreen] 比例]);

CGContextRefeffectInContext=UIGraphicsGetCurrentContext();

CGContextScaleCTM(effectInContext, 1.0, -1.0);

CGContextTranslateCTM(ef

fectInContext, 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, }; const int32_t divisor = 256; NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]); int16_t saturationMatrix[matrixSize]; for (NSUInteger i = 0; i< matrixSize; ++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/* File: UIImage+ImageEffects.h Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur. Version: 1.0 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple"s copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Copyright (C) 2013 Apple Inc. All Rights Reserved. Copyright © 2013 Apple Inc. All rights reserved. WWDC 2013 License NOTE: This Apple Software was supplied by Apple as part of a WWDC 2013 Session. Please refer to the applicable WWDC 2013 Session for further information. IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a non-exclusive license, under Apple"s copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EA1002 5/3/2013 */ @import UIKit; @interface UIImage (ImageEffects) - (UIImage *)applyLightEffect; - (UIImage *)applyExtraLightEffect; - (UIImage *)applyDarkEffect; - (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor; - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage;

用户评论

冷月花魂

真想有一个磨砂玻璃装饰我的窗户!

    有15位网友表示赞同!

┲﹊怅惘。

毛玻璃可以营造出一种神秘又温馨的感觉吧?

    有6位网友表示赞同!

自繩自縛

不知道什么时候能用到毛玻璃,它看起来很美观。

    有11位网友表示赞同!

非想

毛玻璃在艺术品中是不是常会使用呢?

    有16位网友表示赞同!

半世晨晓。

毛玻璃做成装饰画也挺不错的!

    有18位网友表示赞同!

有阳光还感觉冷

有没有人知道毛玻璃的历史由来啊?

    有19位网友表示赞同!

我一个人

毛玻璃有哪些种类的?

    有9位网友表示赞同!

昂贵的背影

想买一个毛玻璃装饰品,不过不知道哪家店有好货。

    有7位网友表示赞同!

志平

最近装修打算用一些毛玻璃元素,希望效果好呢!

    有10位网友表示赞同!

伪心

毛玻璃能做到完全遮挡外部的视线吗?

    有6位网友表示赞同!

男神大妈

我觉得毛玻璃最适合用于浴室或餐厅吧!

    有7位网友表示赞同!

拥菢过后只剰凄凉

毛玻璃是不是比较容易弄脏啊?

    有15位网友表示赞同!

念初

想找一款简约风的毛玻璃灯罩,不知道在哪里买?

    有19位网友表示赞同!

歆久

学习一下怎样自己制作毛玻璃工艺品,很有意思哦!

    有8位网友表示赞同!

有一种中毒叫上瘾成咆哮i

毛玻璃的颜色种类很多吧,哪种颜色看起来质感最好呢?

    有19位网友表示赞同!

见朕骑妓的时刻

毛玻璃的制作过程比较复杂吗?

    有12位网友表示赞同!

在哪跌倒こ就在哪躺下

毛玻璃和磨砂玻璃有什么区别?

    有11位网友表示赞同!

你身上有刺,别扎我

什么时候可以用上高科技制作的新型毛玻璃呢?

    有20位网友表示赞同!

素婉纤尘

我想用毛玻璃打造一个复古优雅的空间,不知道有没有效果图?

    有16位网友表示赞同!

命该如此

毛玻璃的价格怎么样?

    有16位网友表示赞同!

【探索毛玻璃效果的神奇世界:创意视觉体验全解析】相关文章:

1.蛤蟆讨媳妇【哈尼族民间故事】

2.米颠拜石

3.王羲之临池学书

4.清代敢于创新的“浓墨宰相”——刘墉

5.“巧取豪夺”的由来--米芾逸事

6.荒唐洁癖 惜砚如身(米芾逸事)

7.拜石为兄--米芾逸事

8.郑板桥轶事十则

9.王献之被公主抢亲后的悲惨人生

10.史上真实张三丰:在棺材中竟神奇复活

上一篇:前端开发不同阶段学习资源汇总 下一篇:IEC104至IEC61850数据转换项目案例解析