V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
Elethom
V2EX  ›  iDev

iOS 高性能圖片模糊

  •  
  •   Elethom ·
    Elethom · 2014-08-30 18:00:20 +08:00 · 4819 次点击
    这是一个创建于 3519 天前的主题,其中的信息可能已经有所发展或是发生改变。
    http://blog.projectrhinestone.org/high-performance-ios-box-blur-with-accelerate-framework/

    先將圖片尺寸減半, 然後使用 Accelerate.framework 做三次卷積運算. 模糊半徑的算法來自 WWDC sample code.
    16 条回复    2014-09-01 18:18:24 +08:00
    gonghao
        1
    gonghao  
       2014-08-30 18:22:39 +08:00
    GPUImage 其实也是一个比较好的选择
    txx
        2
    txx  
       2014-08-30 18:27:32 +08:00 via iPhone
    @gonghao 性能差距明显
    satanwoo
        3
    satanwoo  
       2014-08-30 21:51:38 +08:00
    卷积的核函数是用的哪个啊?
    keithellis
        4
    keithellis  
       2014-08-30 21:58:48 +08:00
    satanwoo
        5
    satanwoo  
       2014-08-30 22:00:28 +08:00
    不懂但是觉得
    size_t width = CGImageGetWidth(inImageRef) * .5f;
    size_t height = CGImageGetHeight(inImageRef) * .5f;
    size_t rowBytes = CGImageGetBytesPerRow(inImageRef) * .5f;

    这样真的是先尺寸减半吗?
    hoogle
        6
    hoogle  
       2014-08-30 23:19:21 +08:00
    各种方法都试过, 好像还是没法弄到跟 Twitter 个人页面下拉时候那样流畅的 blur 效果。 哎哎。。
    Elethom
        7
    Elethom  
    OP
       2014-08-30 23:42:20 +08:00 via iPhone
    @satanwoo
    減半在 CGContextDrawImage().
    gonghao
        8
    gonghao  
       2014-08-30 23:42:56 +08:00
    @txx 不要放在 main 里面做,性能问题真不是特别明显,GPUImage 性能真心很不错了
    Elethom
        9
    Elethom  
    OP
       2014-08-30 23:43:11 +08:00 via iPhone
    @hoogle
    我也想知道 Twitter 是怎樣實現的...
    satanwoo
        10
    satanwoo  
       2014-08-30 23:57:29 +08:00
    @Elethom

    谢谢,不太懂这块。
    感觉是好像同时降低了图片的bit数。
    txx
        11
    txx  
       2014-08-31 02:04:45 +08:00
    @gonghao http://code.tutsplus.com/tutorials/adding-blur-effects-on-ios--cms-21488

    看5c...如果你真覺得這個叫做性能不錯...
    wezzard
        12
    wezzard  
       2014-08-31 08:33:39 +08:00
    感覺 GPUImage 在 CoreImage 可以自己寫 Filters 之後可以退休了......
    so898
        13
    so898  
       2014-09-01 01:54:47 +08:00   ❤️ 1
    @hoogle @Elethom
    https://github.com/so898/TwitterBlur

    耍了点小聪明,个人觉得最终效果还不错的样子
    那个高度实在是不乐意算了……
    hoogle
        14
    hoogle  
       2014-09-01 11:51:08 +08:00
    @so898 赞。 但细看还是有点差别, 可能 Twitter 用了更多图或者什么原因。。
    gonghao
        15
    gonghao  
       2014-09-01 14:25:58 +08:00
    @txx 5 & 5c 确实性能会差不少,但是也有优化手段,你给那篇文章里面使用 GPUImage 的方式是最基本的方式(直接通过 UIImage 输出),但是可以用 GPUImageView 来优化一些~当然怎么着都希望能有原生的方式来做,所以更期待 iOS 8 的 Blur Effects。p.s. 用 GPUImage 的另一个原因是模糊选择比这种方式多,效果可控性上也更强
    perrywky
        16
    perrywky  
       2014-09-01 18:18:24 +08:00   ❤️ 1
    我的做法是准备好一张模糊效果的图片,盖在原图上面,初始状态完全透明,下拉的时候,降低这张图片的透明度,效果也还不错。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4770 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 09:50 · PVG 17:50 · LAX 02:50 · JFK 05:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.