最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS給圖片添加濾鏡&使用openGLES動態(tài)渲染圖片詳解及實例

 更新時間:2016年10月30日 10:19:14   投稿:lqh  
這篇文章主要介紹了iOS給圖片添加濾鏡&使用openGLES動態(tài)渲染圖片詳解及實例的相關(guān)資料,需要的朋友可以參考下

iOS給圖片添加濾鏡&使用openGLES動態(tài)渲染圖片

給圖片增加濾鏡有這兩種方式: CoreImage / openGLES

 下面先說明如何使用CoreImage給圖片添加濾鏡, 主要為以下步驟:

#1.導(dǎo)入CIImage格式的原始圖片

#2.創(chuàng)建CIFilter濾鏡

#3.用CIContext將濾鏡中的圖片渲染出來

#4.導(dǎo)出渲染后的圖片

參考代碼:

//導(dǎo)入CIImage
  CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"hua"]];
  
  //創(chuàng)建出Filter濾鏡
  CIFilter *filter = [CIFilter filterWithName:@"CIPixellate"];
  
  [filter setValue:ciImage forKey:kCIInputImageKey];
  
  [filter setDefaults];
  
  CIImage *outImage = [filter valueForKey:kCIOutputImageKey];
  
  //用CIContext將濾鏡中的圖片渲染出來
  CIContext *context = [CIContext contextWithOptions:nil];
  
  CGImageRef cgImage = [context createCGImage:outImage
                    fromRect:[outImage extent]];
  
  //導(dǎo)出圖片
  UIImage *showImage = [UIImage imageWithCGImage:cgImage];
  
  CGImageRelease(cgImage);
  
  UIImageView *imageView = [[UIImageView alloc] initWithImage:showImage];
  imageView.center    = self.view.center;
  [self.view addSubview:imageView];

當(dāng)要設(shè)置多個濾鏡的時候, 出了新創(chuàng)建一個CIFilter外還要額外設(shè)定kCIInputAngleKey, 代碼如下:

//導(dǎo)入CIImage
  CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"hua.jpeg"]];
  
  //創(chuàng)建出Filter濾鏡
  CIFilter *filter = [CIFilter filterWithName:@"CIPixellate"];
  
  [filter setValue:ciImage forKey:kCIInputImageKey];
  
  [filter setDefaults];
  
  CIImage *outImage = [filter valueForKey:kCIOutputImageKey];
  
  CIFilter *filterTwo = [CIFilter filterWithName:@"CIHueAdjust"];
  
  [filterTwo setValue:outImage forKey:kCIInputImageKey];
  
  [filterTwo setDefaults];
  
  [filterTwo setValue:@(1.0f) forKey:kCIInputAngleKey]; //如果不增加這行新增的濾鏡不會生效
  
  CIImage *outputImage = [filterTwo valueForKey:kCIOutputImageKey];
  
  //用CIContext將濾鏡中的圖片渲染出來
  CIContext *context = [CIContext contextWithOptions:nil]; 
  
  CGImageRef cgImage = [context createCGImage:outputImage
                    fromRect:[outputImage extent]];
  
  //導(dǎo)出圖片
  UIImage *showImage = [UIImage imageWithCGImage:cgImage];
  
  CGImageRelease(cgImage);
  
  UIImageView *imageView = [[UIImageView alloc] initWithImage:showImage];
  imageView.center    = self.view.center;
  [self.view addSubview:imageView];

下面來介紹怎么用openGLES來使用濾鏡渲染圖片

使用openGlES的步驟大致如下:

#1.導(dǎo)入要渲染的圖片

#2.獲取OpenGLES渲染的上下文

#3.創(chuàng)建出渲染的GLKView buffer

#4.創(chuàng)建CoreImage的上下文

#5.進行CoreImage的相關(guān)設(shè)置

#6.開始渲染并顯示圖片

參考代碼如下:

//導(dǎo)入要渲染的圖片
  UIImage *showImage = [UIImage imageNamed:@"hua.jpeg"];
  CGRect rect    = CGRectMake(0, 0, showImage.size.width, showImage.size.height);
  
  //獲取OpenGLES渲染的上下文
  EAGLContext *eagContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
  
  //創(chuàng)建出渲染的buffer
  GLKView *glkView = [[GLKView alloc] initWithFrame:rect
                       context:eagContext];
  [glkView bindDrawable];
  [self.view addSubview:glkView];
  
  //創(chuàng)建出CoreImage的上下文
  CIContext *ciContext = [CIContext contextWithEAGLContext:eagContext
                           options:@{kCIContextWorkingColorSpace: [NSNull null]}];
  
  //CoreImage相關(guān)設(shè)置
  CIImage *ciImage = [[CIImage alloc] initWithImage:showImage];
  
  CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"];
  
  [filter setValue:ciImage forKey:kCIInputImageKey];
  [filter setValue:@(0) forKey:kCIInputIntensityKey];
  
  //開始渲染
  [ciContext drawImage:[filter valueForKey:kCIOutputImageKey]
         inRect:CGRectMake(0, 0, glkView.drawableWidth, glkView.drawableHeight)
        fromRect:[ciImage extent]];
  
  [glkView display];

如果要動態(tài)渲染, 可以通過UISilder動態(tài)調(diào)整一下代碼的vaule值

[filter setValue:vaule forKey:kCIInputIntensityKey];

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • iOS App設(shè)計模式開發(fā)中對迭代器模式的使用示例

    iOS App設(shè)計模式開發(fā)中對迭代器模式的使用示例

    這篇文章主要介紹了iOS App設(shè)計模式開發(fā)中對迭代器模式的使用示例,示例代碼為傳統(tǒng)的Objective-C,需要的朋友可以參考下
    2016-03-03
  • iOS圖片拉伸技巧(iOS5.0、iOS6.0)

    iOS圖片拉伸技巧(iOS5.0、iOS6.0)

    這篇文章主要為大家詳細介紹了iOS圖片拉伸技巧,提供了3種圖片拉伸的解決方案,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • ios開發(fā)UITableViewCell圖片加載優(yōu)化詳解

    ios開發(fā)UITableViewCell圖片加載優(yōu)化詳解

    這篇文章主要為大家介紹了ios開發(fā)UITableViewCell圖片加載優(yōu)化的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • 如何去掉Xcode工程中某種類型的警告

    如何去掉Xcode工程中某種類型的警告

    這篇文章主要給大家介紹了關(guān)于如何去掉Xcode工程中某種類型的警告,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用Xcode具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • swift 單例的實現(xiàn)方法及實例

    swift 單例的實現(xiàn)方法及實例

    這篇文章主要介紹了swift 單例的實現(xiàn)方法及實例的相關(guān)資料,需要的朋友可以參考下
    2017-07-07
  • iOS 彈幕功能的實現(xiàn)思路圖解

    iOS 彈幕功能的實現(xiàn)思路圖解

    這篇文章主要介紹了iOS 彈幕功能的實現(xiàn)思路圖文詳解,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-07-07
  • iOS 四種回調(diào)方法總結(jié)

    iOS 四種回調(diào)方法總結(jié)

    這篇文章主要介紹了iOS 四種回調(diào)方法總結(jié)的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • iOS中導(dǎo)航欄的基本使用匯總

    iOS中導(dǎo)航欄的基本使用匯總

    導(dǎo)航欄作為iOS開發(fā)的一大空控件來說,是非常的重要這篇文章主要給大家介紹了關(guān)于iOS中導(dǎo)航欄的基本使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • 詳解iOS 用于解決循環(huán)引用的block timer

    詳解iOS 用于解決循環(huán)引用的block timer

    這篇文章主要介紹了詳解iOS 用于解決循環(huán)引用的block timer,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • iOS 中Swift仿微信添加提示小紅點功能(無數(shù)字)

    iOS 中Swift仿微信添加提示小紅點功能(無數(shù)字)

    這篇文章主要介紹了iOS 中Swift仿微信添加提示小紅點功能(無數(shù)字),非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-05-05

最新評論

罗甸县| 天镇县| 桂阳县| 马山县| 岳普湖县| 白银市| 井研县| 遂川县| 仙桃市| 朝阳县| 汝南县| 花垣县| 岗巴县| 潮安县| 汉川市| 宿松县| 岳西县| 宁都县| 萍乡市| 安溪县| 武强县| 镇巴县| 阆中市| 山东省| 方正县| 策勒县| 柘城县| 读书| 饶平县| 大同市| 鹤山市| 武乡县| 涟源市| 育儿| 清丰县| 榕江县| 临漳县| 乾安县| 兖州市| 原阳县| 和田县|