码迷,mamicode.com
首页 > 移动开发 > 详细

[翻译] ios-image-filters

时间:2014-11-02 08:12:12      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   os   ar   使用   

ios-image-filters

bubuko.com,布布扣

https://github.com/esilverberg/ios-image-filters

photoshop-style filter interface for UIImage class on iOS to make instagram-style images

photoshop-风格的滤镜接口,可以像使用photshop那样子来配置图片。

 

ios-image-filters

These days everyone seems to want instagram-style filters for images on iPhone. The way to do this (I think) is to examine how people have implemented equivalent filters in Photoshop and code them in objective c. Unfortunately, the imaging libraries are all geared for gaming. For non-game developers who just want simple image processing, this is overkill.

这些日子里,大家都想用具备设置风格的滤镜来处理图片。为了达到这个目的,大家需要研究Photoshop中使用的滤镜以及OC代码中等效的滤镜,很不幸,这些图片滤镜全部都是为游戏开发设计,对于非游戏开发人员,即使只想用最简单的图片处理,这也无异于自杀。

 

It‘s like photoshop for the UIImage class!

I‘ve worked hard to mimic the photoshop color adjustment menus. Turns out these are clutch in pretty much all the best image filters you can name right now (lomo, polaroid). For example, if you want to manipulate levels, here‘s your method, built straight onto the UIImage class:

只是模拟photoshop的颜色平衡的菜单都费了好大的劲。为了调节到能达到指定的效果花了好多好多时间。不过已经很好用了,你可以看如下的例子:

- (UIImage*) levels:(NSInteger)black mid:(NSInteger)mid white:(NSInteger)white

An API just like that cool menu in Photoshop!

Want to do a curves adjustment to mimic a filter you saw on a blog? Just do this:

一个API与Photoshop中的一个菜单非常相似!

能够微调一个滤镜的效果么?用以下的方式即可:

NSArray *redPoints = [NSArray arrayWithObjects:
        [NSValue valueWithCGPoint:CGPointMake(0, 0)],
        [NSValue valueWithCGPoint:CGPointMake(93, 76)],
        [NSValue valueWithCGPoint:CGPointMake(232, 226)],
        [NSValue valueWithCGPoint:CGPointMake(255, 255)],
        nil];
NSArray *bluePoints = [NSArray arrayWithObjects:
         [NSValue valueWithCGPoint:CGPointMake(0, 0)],
         [NSValue valueWithCGPoint:CGPointMake(57, 59)],
         [NSValue valueWithCGPoint:CGPointMake(220, 202)],
         [NSValue valueWithCGPoint:CGPointMake(255, 255)],
         nil];
UIImage *image = [[[UIImage imageNamed:@"landscape.jpg" applyCurve:redPoints toChannel:CurveChannelRed] 
 applyCurve:bluePoints toChannel:CurveChannelBlue];

The problem with my curves implementation is that I didn‘t use the same kind of curve algorithm as Photoshop uses. Mainly, because I don‘t know how, and other than the name of the curve (bicubic) all the posts and documentation I simply don‘t understand or cannot figure out how to port to iOS. But, the curves I use (catmull-rom) seem close enough.

其实还是有问题的,因为我实现的方式与Photoshop并不一致。主要原因是,我不知道Photoshop的相关滤镜是怎么实现出来的,我只能从iOS的找到类似的效果来替换。

 

How to integrate

Copy and paste the ImageFilter.* and Curves/* classes into your project. It‘s implemented a Category on UIImage.

怎么使用呢?复制粘贴ImageFilter.*与Curves.*类到你的项目工程中。他们都是UIImage的category的方式实现的,简单易用。

 

How to use

#import "ImageFilter.h"
UIImage *image = [UIImage imageNamed:@"landscape.jpg"];
self.imageView.image = [image sharpen];
// Or
self.imageView.image = [image saturate:1.5];
// Or
self.imageView.image = [image lomo];

 

What is still broken

  • Gaussian blur is slow! 高斯模糊很慢!
  • More blend modes for layers 更多的针对Layer的混合模式
  • Curves are catmull rom, not bicubic ???
  • So much else... 就这些...

 

Other options

I tried, but mostly failed, to understand these libraries. Simple Image Processing is too simple, and uses a CPP class to accomplish its effects, as does CImg. I find the CPP syntax ghoulish, to say the least. I stared at the GLImageProcessing code for hours, and still don‘t understand what‘s going on. Guess I should have taken CS244a...

为了理解这些库怎么用,我试过了,但绝大部分都失败了。简单的图片处理是很简单的,包括用CPP类来实现这些效果,还有CImg。我发现CPP的语法格式太恐怖而放弃了。我尝试了GLImageProcessing几个小时候,因为实在不知道他们是怎么出来效果的-_-!!,也许我该试一下CS244a...

UPDATE: Core image filters in iOS5 are probably what you want to use going forward, though they are not backwards-compatible with iOS4 or earlier.

更新:在iOS5上,Core image滤镜就是你以后要使用的工具了,虽然他们不会向前兼容iOS4之前的版本。

License

MIT License, where applicable. I borrowed code from this project:http://sourceforge.net/projects/curve/files/ , which also indicates it is MIT-licensed.http://en.wikipedia.org/wiki/MIT_License

There is also now code adapted from ImageMagick, whose license may be found at:http://www.imagemagick.org/script/license.php

[翻译] ios-image-filters

标签:des   style   blog   http   io   color   os   ar   使用   

原文地址:http://www.cnblogs.com/YouXianMing/p/4068338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!