欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS圖片模糊效果的實現(xiàn)方法

 更新時間:2016年09月30日 10:38:20   作者:vbirdbest  
這篇文章主要為大家詳細(xì)介紹了iOS圖片模糊效果的三種實現(xiàn)方式,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文為大家分享了iOS圖片模糊效果的三種實現(xiàn)方式,供大家參考,具體內(nèi)容如下

1.實現(xiàn)效果依次如圖:原圖、iOS8效果、Core Image效果、 VImage 效果

-

2. 代碼

#import "ViewController.h" 
#import <Accelerate/Accelerate.h> 
 
@interface ViewController () 
 
@end 
 
@implementation ViewController 
 
- (void)viewDidLoad { 
 [super viewDidLoad]; 
 self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]]; 
  
// [self iOS8BlurImageImplement]; 
// [self coreImageImplement]; 
 [self vImageImplement]; 
} 
 
// iOS8 使用系統(tǒng)自帶的處理方式 
- (void)iOS8BlurImageImplement { 
 UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; 
 UIVisualEffectView *view = [[UIVisualEffectView alloc] initWithEffect:beffect]; 
 view.frame = self.view.bounds; 
 [self.view addSubview:view]; 
} 
 
 
// 使用CoreImage實現(xiàn)圖片模糊 
- (void)coreImageImplement{ 
 CIContext *context = [CIContext contextWithOptions:nil]; 
  
 NSError *error = nil; 
 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"png"]; 
 NSData *imageData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingUncached error:&error]; 
  
 //NSData *imageData = [NSData dataWithContentsOfFile:@"background.png"]; 
 CIImage *image = [CIImage imageWithData:imageData]; 
 CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; 
 [filter setValue:image forKey:kCIInputImageKey]; 
 [filter setValue:@2.0f forKey:@"inputRadius"]; 
 CIImage *result = [filter valueForKey:kCIOutputImageKey]; 
 CGImageRef outImage = [context createCGImage:result fromRect:[result extent]]; 
 UIImage *bluerImage = [UIImage imageWithCGImage:outImage]; 
  
 UIImageView *imageView = [[UIImageView alloc] initWithImage:bluerImage]; 
 imageView.frame = self.view.bounds; 
 [self.view addSubview:imageView]; 
} 
 
 
// 使用vImage API實現(xiàn)圖片模糊 
// iOS5.0中新增了vImage API可以使用,它屬于Accelerate.Framework,所以如果你要使用它要在工程中加入這個Framework。模糊算法使用的是vImageBoxConvolve_ARGB8888這個函數(shù)。 
- (void)vImageImplement { 
 UIImage *image = [UIImage imageNamed:@"background"]; 
 UIImage *blurImage = [self blurryImage:image withBlurLevel:0.5]; 
 self.view.backgroundColor = [UIColor colorWithPatternImage:blurImage]; 
} 
 
- (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur { 
 if (blur < 0.f || blur > 1.f) { 
  blur = 0.5f; 
 } 
 int boxSize = (int)(blur * 100); 
 boxSize = boxSize - (boxSize % 2) + 1; 
  
 CGImageRef img = image.CGImage; 
  
 vImage_Buffer inBuffer, outBuffer; 
 vImage_Error error; 
  
 voidvoid *pixelBuffer; 
  
 CGDataProviderRef inProvider = CGImageGetDataProvider(img); 
 CFDataRef inBitmapData = CGDataProviderCopyData(inProvider); 
  
 inBuffer.width = CGImageGetWidth(img); 
 inBuffer.height = CGImageGetHeight(img); 
 inBuffer.rowBytes = CGImageGetBytesPerRow(img); 
  
 inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData); 
  
 pixelBuffer = malloc(CGImageGetBytesPerRow(img) * 
       CGImageGetHeight(img)); 
  
 if(pixelBuffer == NULL) 
  NSLog(@"No pixelbuffer"); 
  
 outBuffer.data = pixelBuffer; 
 outBuffer.width = CGImageGetWidth(img); 
 outBuffer.height = CGImageGetHeight(img); 
 outBuffer.rowBytes = CGImageGetBytesPerRow(img); 
  
 error = vImageBoxConvolve_ARGB8888(&inBuffer, 
          &outBuffer, 
          NULL, 
          0, 
          0, 
          boxSize, 
          boxSize, 
          NULL, 
          kvImageEdgeExtend); 
  
  
 if (error) { 
  NSLog(@"error from convolution %ld", error); 
 } 
  
 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
 CGContextRef ctx = CGBitmapContextCreate( 
            outBuffer.data, 
            outBuffer.width, 
            outBuffer.height, 
            8, 
            outBuffer.rowBytes, 
            colorSpace, 
            kCGImageAlphaNoneSkipLast); 
 CGImageRef imageRef = CGBitmapContextCreateImage (ctx); 
 UIImage *returnImage = [UIImage imageWithCGImage:imageRef]; 
  
 //clean up 
 CGContextRelease(ctx); 
 CGColorSpaceRelease(colorSpace); 
  
 free(pixelBuffer); 
 CFRelease(inBitmapData); 
  
 CGColorSpaceRelease(colorSpace); 
 CGImageRelease(imageRef); 
  
 return returnImage; 
} 
 
@end 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS支付寶支付方法詳解

    iOS支付寶支付方法詳解

    這篇文章主要為大家詳細(xì)介紹了iOS支付寶支付方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • IOS10 解決權(quán)限崩潰問題詳解

    IOS10 解決權(quán)限崩潰問題詳解

    這篇文章主要介紹了IOS10 解決權(quán)限崩潰問題詳解方法的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • iOS實現(xiàn)富文本編輯器的方法詳解

    iOS實現(xiàn)富文本編輯器的方法詳解

    大家在開發(fā)的時候經(jīng)常會用到富文本編輯器,所以這篇文章就給大家整理了如何使用iOS實現(xiàn)富文本編輯器的方法,相信本文對大家具有一定的參考借鑒價值,有需要的朋友們可以一起來看看。
    2016-10-10
  • 簡單掌握iOS應(yīng)用開發(fā)中sandbox沙盒的使用

    簡單掌握iOS應(yīng)用開發(fā)中sandbox沙盒的使用

    這篇文章主要介紹了iOS應(yīng)用開發(fā)中sandbox沙盒的使用,即將應(yīng)用的存儲區(qū)域單獨隔離開來,開發(fā)時經(jīng)常可以用到,需要的朋友可以參考下
    2016-01-01
  • 如何使用IOS自動化測試工具UIAutomation

    如何使用IOS自動化測試工具UIAutomation

    這篇文章主要介紹了UIAutomation使用實例、應(yīng)用技巧、基本知識點總結(jié)和需要注意事項,具有一定的參考價值
    2021-04-04
  • iOS自定義button抖動效果并實現(xiàn)右上角刪除按鈕

    iOS自定義button抖動效果并實現(xiàn)右上角刪除按鈕

    這篇文章主要為大家詳細(xì)介紹了iOS自定義button抖動效果并實現(xiàn)右上角刪除按鈕的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • iOS簡單到無門檻調(diào)試WebView的步驟詳解

    iOS簡單到無門檻調(diào)試WebView的步驟詳解

    這篇文章主要給大家介紹了關(guān)于iOS調(diào)試WebView的相關(guān)資料,文中介紹的方法可以說是非常簡單,簡單到無門檻,通過圖文介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • iOS畫出精美的圖表方法示例

    iOS畫出精美的圖表方法示例

    這篇文章主要給大家介紹了關(guān)于iOS如何畫出精美的圖表的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-08-08
  • iOS使用CIFilter生成二維碼

    iOS使用CIFilter生成二維碼

    這篇文章主要介紹了iOS使用CIFilter生成二維碼,二維碼的生成和讀取只需要使用Core Image框架和AVFoundation框架就能輕松實現(xiàn)。在這里,我們主要介紹二維碼的生成。有興趣的可以了解一下
    2017-12-12
  • iOS動畫特效之立方體翻轉(zhuǎn)

    iOS動畫特效之立方體翻轉(zhuǎn)

    今天起為大家?guī)韎OS動畫特效合集之立方體翻轉(zhuǎn),APP如美女,動畫如衣裳,趕緊為她披上漂亮的衣裝吧!
    2016-08-08

最新評論