Processing Images(处理图像)

Core Image提供了一系列内置过滤器来处理图像,如CIFilter,它具有可变参数以产生输出图像。CIImage对象不可变,可以从多种来源创建。创建CIContext对象用于渲染图像,iOS上可使用GPU或CPU渲染。为了实时性能,可以使用EAGLContext创建CIContext。通过设置CIFilter的参数并获取输出图像,然后渲染结果图像。滤镜可以链接以创建复杂效果,例如使用CIGloom和CIBumpDistortion。Core Image还支持过渡效果和视频过滤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Processing Images(处理图像)

  Core Image has three classes thatsupport image processing on iOS and OS X:(在IOS和OS X上 Core Image 有三个类支持图像的处理)

· CIFilter is a mutable object that represents an effect. A filter object hasat least one input parameter and produces an outputimage.(CIFilter是一个可变对象,代表了一种效果。一个过滤器对象至少有一个输入参数,产生一个输出图像。CIFilter是个滤镜类,Core Image框架中对图片属性进行细节处理的类。它对所有的像素进行操作,用一些键-值设置来决定具体操作的程度)

· CIImage is an immutable object that represents an image. You can synthesize image data orprovide it from a file or the output of anotherCIFilter object.(CIImage是一个不可变对象,代表了一种形象。你可以从一个文件或合成图像数据或提供另一个CIFilter对象的输出)

   CIContext is an object through which Core Image    draws the results produced by a filter. ACore Image

context can be based on the CPU or the GPU.(CIContext是物体通过其核心图像绘制的滤波器产生的结果。  CIContext可以基于CPU或GPU)

   The remainder of this chapterprovides all the details you need to use Core Image filters and theCIFilter,CIImage, andCIContext classes on iOS and OS X.(本章提供了所有的细节,你需要使用的Core Image滤镜和CIFilter,CIImage和CIContext的所有细节,在iOS和OS X上)

Overview(概要)

   Processing an image isstraightforward as shown in Listing 1-1. Thisexample uses Core Image methods specific to iOS; see below for thecorresponding OS X methods. Each numbered step in the listing is described inmore detail following the listing.(处理简单的图像,如清单1-1所示。这个例子使用核心图像的方法具体到iOS;看下面相应的OS X的方法。在清单中的每一个编号的步骤在上市后更详细地描述)

Note: To use Core Image in your app, youshould add the framework to your Xcode project (CoreImage.framework on iOS orQuartzCore.framework on OS X) and import the corresponding header inyour source code files (

CIContext *context = [CIContext  contextWithOptions:nil];     //1

CIImage *image = [CIImage imageWithContentsOfURL:myURL];   // 2

CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"];   // 3 CISepiaTone是过滤器滤镜效果的滤镜名字

[filter  setValue: image  forKey:kCIInputImageKey];//标识需要修改的原图像

[filter setValue:@0.8f  forKey: kCIInputIntensityKey];//滤镜的参数名和设置的参数值

CIImage *result = [filter valueForKey:kCIOutputImageKey];  // 4滤镜后的效果

CGRect extent = [result  extent];

CGImageRef cgImage = [context   createCGImage: result  fromRect: extent]; // 5

上面代码的解释:

Here’swhat the code does:(
设置输入的参数值的方法,可参考下面的Creating a CIFilter Object and SettingValues详细查看))

  1. Create aCIContext object.ThecontextWithOptions: method isonly available on iOS. For details on other methods for iOS and OS X seeTable 1-2.(创建CIContext对象, contextWithOptions的方法只适用于IOS上,其他适用于IOS和 OS X上的具体的方法,参考下图Table1-2.)

  2. Create aCIImage object.You can create aCIImage from a variety ofsources, such as a URL. SeeCreating a CIImage Object for moreoptions.(创建一个CIImage对象。您可以创建一个CIImage从各种各样的来源,如一个URL。参考下面的Creating a CIImage Object查看更多创建一个CIImage对象的方法)

  3. .Create the filter andset values for its input parameters. There are more compact ways to set valuesthan shown here. SeeCreating a CIFilter Object and SettingValues.(创建过滤器,并设置输入的参数Values值,有很多

  4. Get the output image. The output image is arecipe for how to produce the image. The image is not yet rendered. SeeGetting the Output Image.(得到一个输出的CIImage对象,这个输出对象是为如何产生一个image做准备的材料,可参考下面的Getting the Output Image详细查看)

  5. Render theCIImage to a CoreGraphics image that is ready for display or saving to a file.(渲染一个CIImage成核心图形图像,为显示或者保存一个文件做准备)

    Important: SomeCore Image filters produce images of infinite extent, such as those in theCICategoryTileEffect category. Prior to rendering, infinite images must eitherbe cropped (CICrop filter) or you must specify a rectangle of finite dimensionsfor rendering the image.(一些核心图像过滤器产生无限范围的图像,比如那些CICategoryTileEffect类别。渲染之前,无限的图片必须是剪裁(CICrop过滤器)或者你必须指定一个矩形的有限维渲染图像放大)

The Built-in Filters(内置的过滤器)

  Core Image comes with dozens ofbuilt-in filters ready to support image processing in your app.Core Image Filter Reference liststhese filters, their characteristics, their iOS and OS X availability, andshows a sample image produced by the filter.The list ofbuilt-in filters can change, so for that reason,Core Image provides methods that let you query the system for theavailable filters(seeQuerying the System for Filters).

翻译:CoreImage为你的app提供了许多内置的过滤器,来支持对图像进行处理。Core Image Filter Reference提供了很多过滤器。显示由过滤器产生的示例图像。内置的过滤器列表可以改变,所以,因为这个原因,核心图像提供的方法,让您查询可用的过滤器的系统。

   A filter category specifies the type of effect—blur,distortion, generator, and so forth—or its intended use—still images, video,nonsquare pixels, and so on. A filter can be a member of more than onecategory. A filter also has a display name,which is the name to show to users and afiltername, which is the name you must use to access the filterprogrammatically.

翻译:一个过滤器类别指定的效果,模糊、失真、发电机的类型,等等,或其使用静止图像、视频、非方形像素,等等。过滤器可以是一个以上的类的成员。过滤器也显示名称,这是展示给用户的名字和一个过滤器的名称,其名称必须使用访问过滤程序。

   Most filters have one or more input parameters that let you control how processing is done. Each input parameter has anattribute class that specifies its data type, such asNSNumber. An input parameter can optionally have other attributes, such as its default value, the allowable minimum and maximum values, the display name for the parameter, and any other attributes that are described inCIFilter Class Reference.

翻译:大多数的过滤器有一个或多个输入参数,让您控制如何完成处理。每个输入参数有一个属性类,指定其数据类型,比如NSNumber。一个输入参数可以有其他属性,如它的默认值,允许的最大值和最小值,该参数的显示名称和其他属性,在CIFilter Class Reference.参考描述

  For example, the CIColorMonochromefilter has three input parameters—the image to process, a monochrome color, andthe color intensity. You supply the image and have the option to set a colorand its intensity. Most filters, including the CIColorMonochrome filter, havedefault values for each nonimage input parameter. Core Image uses the defaultvalues to process your image if you choose not to supply your own values for theinput parameters.

翻译:例如 CIColorMonochrome滤波器有三个参数,图像处理参数的设置,黑白色参数的设置,颜色强度参数的设置,你需要提供图片,可以选择设置颜色和强度。包括CIColorMonochrome滤波器在内的大多数滤波器,它们的参数一般都有默认值,如果你不设置参数值的话,那就默认为是默认值,然后来为你处理你选择的图片。

   Filter attributes are stored askey-value pairs. The key is a constant that identifies the attribute and thevalue is the setting associated with the key. Core Image attribute values aretypically one of the data types listed in Table 1-1.

翻译:滤波器的参数是以键值对的方式存储的,键是一个常数,标识属性和值是与键关联的设置。Core Image属性的值通常是一个数据类型的表1-1列出

  Core Image uses key-value coding, which means you can get and set values for the attributes of a filter by using the methods provided by theNSKeyValueCoding protocol. (For more information, seeKey-Value Coding Programming Guide.)

Creating a Core ImageContext

  To renderthe image, you need to create a Core Image context and then use that context todraw the output image. A Core Image context represents a drawing destination.The destination determines whether Core Image uses the GPU or the CPU forrendering. Table 1-2 lists the various methodsyou can use for specific platforms and renderers

翻译:要渲染图像,您需要创建一个核心图像上下文,然后使用该上下文来绘制输出图像。一个核心图像上下文表示一个绘图目标。目的确定Core Image使用的是GPU还是 CPU渲染。表1 - 2列出了针对特定平台和渲染器的各种方法可以使用。

 Creating a Core ImageContext on iOS When You Don’t Need Real-TimePerformance

  If your app doesn’t require real-time display, you can create aCIContext object as follows:
CIContext *context = [CIContext contextWithOptions:nil];
  This method can use either the CPUor GPU for rendering. To specify which to use, set up an options dictionary andadd the keykCIContextUseSoftwareRenderer with the appropriate Boolean value foryour app. CPU rendering isslower than GPU rendering.But in the case of GPU rendering, the resultingimage is not displayed untilafter it is copied back to CPU memory and converted to another imagetype such as aUIImage object.

翻译:这种方法可以使用CPU或GPU渲染。指定使用,设置一个选项字典和添加你的应用程序的相应的布尔值的关键kCIContextUseSoftwareRenderer。CPU渲染比GPU渲染速度慢。但在GPU渲染的情况下,由此产生的图像不显示,直到它复制回CPU内存和转换到另一个图像类型如UIImage对象

Creating a Core Image Contexton iOS When You Need

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值