iOS Developer Library

Developer

CoreImage Framework Reference CIColor Class Reference

Options
Deployment Target:

On This Page
Language:

CIColor

The CIColor class contains color values and the color space for which the color values are valid. You use CIColor objects in conjunction with other Core Image classes, such as CIFilter, CIContext,and CIImage, to take advantage of the built-in Core Image filters when processing images.

A color space defines a one-, two-, three-, or four-dimensional environment whose color components represent intensity values. A color component is also referred to as a color channel. An RGB color space, for example, is a three-dimensional color space whose stimuli are the red, green, and blue intensities that make up a given color. Regardless of the color space, in Core Image, color values range from 0.0 to 1.0, with 0.0 representing an absence of that component (0 percent) and 1.0 representing 100 percent.

Colors also have an alpha component that represents the opacity of the color, with 0.0 meaning completely transparent and 1.0 meaning completely opaque. If a color does not have an explicit alpha component, Core Image paints the color as if the alpha component equals 1.0. You always provide unpremultiplied color components to Core Image and Core Image provides unpremultiplied color components to you. Core Image premultiplies each color component with the alpha value in order to optimize calculations. For more information on premultiplied alpha values see Core Image Programming Guide.

Inheritance


Conforms To


Import Statement


Swift

import CoreImage

Objective-C

@import CoreImage;

Availability


Available in iOS 5.0 and later.
  • Initializes a Core Image color object with a Core Graphics color.

    Declaration

    Swift

    init!(CGColor c: CGColor!)

    Objective-C

    - (id)initWithCGColor:(CGColorRef)c

    Parameters

    c

    A Core Graphics color value.

    Return Value

    The resulting Core Image color.

    Discussion

    A CGColorRef object is the fundamental opaque data type used internally by Core Graphics to represent colors. For more information on Core Graphics color and color spaces, see Quartz 2D Programming Guide.

    You can pass a CGColorRef object that represents any color space, including CMYK, but Core Image converts all color spaces to the Core Image working color space before it passes the color space to the filter kernel. The Core Image working color space uses three color components plus alpha.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

  • Initializes a Core Image color object using a UIKit color object.

    Declaration

    Swift

    init?(color color: UIColor)

    Objective-C

    - (instancetype)initWithColor:(UIColor *)color

    Parameters

    color

    The initial color value, which can belong to any available colorspace.

    Return Value

    The resulting Core Image color.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Creates a color object from a Quartz color.

    Declaration

    Objective-C

    + (CIColor *)colorWithCGColor:(CGColorRef)c

    Parameters

    c

    A Quartz color (CGColorRef object) created using a Quartz color creation function such as CGColorCreate.

    Return Value

    A Core Image color object that represents a Quartz color.

    Discussion

    A CGColorRef object is the fundamental opaque data type used internally by Quartz to represent colors. For more information on Quartz 2D color and color spaces, see Quartz 2D Programming Guide.

    You can pass a CGColorRef object that represents any color space, including CMYK, but Core Image converts all color spaces to the Core Image working color space before it passes the color space to the filter kernel. The Core Image working color space uses three color components plus alpha.

    Import Statement

    Objective-C

    @import CoreImage;

    Availability

    Available in iOS 5.0 and later.

  • Creates a color object using the specified RGB color component values

    Declaration

    Swift

    init!(red r: CGFloat, green g: CGFloat, blue b: CGFloat) -> CIColor

    Objective-C

    + (CIColor *)colorWithRed:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b

    Parameters

    r

    The value of the red component.

    g

    The value of the green component.

    b

    The value of the blue component.

    Return Value

    A Core Image color object that represents an RGB color in the color space specified by the Quartz 2D constant kCGColorSpaceGenericRGB.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

  • Creates a color object using the specified RGBA color component values.

    Declaration

    Swift

    init!(red r: CGFloat, green g: CGFloat, blue b: CGFloat, alpha a: CGFloat) -> CIColor

    Objective-C

    + (CIColor *)colorWithRed:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b alpha:(CGFloat)a

    Parameters

    r

    The value of the red component.

    g

    The value of the green component.

    b

    The value of the blue component.

    a

    The value of the alpha component.

    Return Value

    A Core Image color object that represents an RGB color in the color space specified by the Quartz 2D constant kCGColorSpaceGenericRGB and an alpha value.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

  • Creates a color object using the RGBA color component values specified by a string.

    Declaration

    Swift

    init!(string representation: String!) -> CIColor

    Objective-C

    + (CIColor *)colorWithString:(NSString *)representation

    Parameters

    representation

    A string that is in one of the formats returned by the stringRepresentation method. For example, the string:

    @"0.5 0.7 0.3 1.0"

    indicates an RGB color whose components are 50% red, 70% green, 30% blue, and 100% opaque (alpha value of 1.0). The string representation always has four components—red, green, blue, and alpha. The default value for the alpha component is 1.0.

    Return Value

    A Core Image color object that represents an RGB color in the color space specified by the Quartz 2D constant kCGColorSpaceGenericRGB.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

  • Returns the alpha value of the color.

    Declaration

    Swift

    func alpha() -> CGFloat

    Objective-C

    - (CGFloat)alpha

    Return Value

    The alpha value. A color created without an explicit alpha value has an alpha of 1.0 by default.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

    See Also

    – components

  • Returns the blue component of the color.

    Declaration

    Swift

    func blue() -> CGFloat

    Objective-C

    - (CGFloat)blue

    Return Value

    The unpremultiplied blue component of the color.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

    See Also

    – components

  • Returns the Quartz 2D color space associated with the color.

    Declaration

    Swift

    func colorSpace() -> Unmanaged<CGColorSpace>!

    Objective-C

    - (CGColorSpaceRef)colorSpace

    Return Value

    The Quartz 2D color space (CGColorSpaceRef object).

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

    See Also

    – components

  • Returns the color components of the color.

    Declaration

    Swift

    func components() -> UnsafePointer<CGFloat>

    Objective-C

    - (const CGFloat *)components

    Return Value

    An array of color components, specified as floating-point values in the range of 0.0 through 1.0. This array includes an alpha component if there is one.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

  • Returns the green component of the color.

    Declaration

    Swift

    func green() -> CGFloat

    Objective-C

    - (CGFloat)green

    Return Value

    The unpremultiplied green component of the color.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

    See Also

    – components

  • Returns the number of color components in the color.

    Declaration

    Swift

    func numberOfComponents() -> UInt

    Objective-C

    - (size_t)numberOfComponents

    Return Value

    The number of color components, which includes an alpha component if there is one.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

    See Also

    – components

  • Returns the red component of the color.

    Declaration

    Swift

    func red() -> CGFloat

    Objective-C

    - (CGFloat)red

    Return Value

    The unpremultiplied red component of the color.

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

    See Also

    – components

  • Returns a formatted string that specifies the components of the color.

    Declaration

    Swift

    func stringRepresentation() -> String!

    Objective-C

    - (NSString *)stringRepresentation

    Return Value

    The formatted string.

    Discussion

    The string representation always has four components—red, green, blue, and alpha. The default value for the alpha component is 1.0. For example, this string:

    @"0.5 0.7 0.3 1.0"

    indicates an RGB color whose components are 50% red, 70% green, 30% blue, and 100% opaque (alpha value of 1.0).

    Import Statement

    Objective-C

    @import CoreImage;

    Swift

    import CoreImage

    Availability

    Available in iOS 5.0 and later.

    See Also

    – components