Show / Hide Table of Contents

# Class ColorSpace

This abstract class is used to serve as a color space tag to identify the specific color space of a Color object. It contains methods that transform colors in a specific color space to/from several color space such as DeviceRGB and DeviceCMYK.

For purposes of the methods in this class, colors are represented as arrays of color components represented as doubles in a normalized range defined by each ColorSpace. For many ColorSpaces (e.g. DeviceRGB), this range is 0.0 to 1.0. However, some ColorSpaces have components whose values have a different range. Methods are provided to inquire per component minimum and maximum normalized values.

##### Inheritance

object
ColorSpace

##### Implements

IDisposable

##### Inherited Members

object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()

###### Namespace: pdftron.PDF

###### Assembly: PDFTronDotNet.dll

##### Syntax

    public class ColorSpace : IDisposable

##### Remarks

Note that in Pattern color space (i.e. for ColorSpace::e_pattern) 'color values' are PDF::PatternColor objects instead of the numeric component values (i.e. ColorPt) used with other spaces.

### Constructors

#### ColorSpace(Obj)

Create a ColorSpace from the given SDF/Cos object listed under ColorSpaces entry in page Resource dictionary. If color_space dictionary is null, a non valid ColorSpace object is created.

##### Declaration

    public ColorSpace(Obj cs_dict)

##### Parameters

Type | Name | Description
--- | --- | ---
Obj | cs_dict | the color_space

### Methods

#### Convert2CMYK(ColorPt, ColorPt)

A convenience function used to convert color points from the current color space to DeviceCMYK color space.

##### Declaration

    public virtual void Convert2CMYK(ColorPt in_color, ColorPt out_color)

##### Parameters

Type | Name | Description
--- | --- | ---
ColorPt | in_color | input color point in the current color space
ColorPt | out_color | output color point in the DeviceCMYK color space

##### Remarks

the number to input colorants must match the number of colorants expected by the current color space.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### Convert2Gray(ColorPt, ColorPt)

A convenience function used to convert color points from the current color space to DeviceGray color space.

##### Declaration

    public virtual void Convert2Gray(ColorPt in_color, ColorPt out_color)

##### Parameters

Type | Name | Description
--- | --- | ---
ColorPt | in_color | input color point in the current color space
ColorPt | out_color | output color point in the DeviceGray color space

##### Remarks

the number to input colorants must match the number of colorants expected by the current color space.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### Convert2RGB(ColorPt, ColorPt)

A convenience function used to convert color points from the current color space to DeviceRGB color space.

##### Declaration

    public virtual void Convert2RGB(ColorPt in_color, ColorPt out_color)

##### Parameters

Type | Name | Description
--- | --- | ---
ColorPt | in_color | input color point in the current color space
ColorPt | out_color | output color point in the DeviceRGB color space

##### Remarks

the number to input colorants must match the number of colorants expected by the current color space.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### Create(Obj)

Create a new ColorSpace from a given object

##### Declaration

    public static ColorSpace Create(Obj color_space)

##### Parameters

Type | Name | Description
--- | --- | ---
Obj | color_space | existing color space

##### Returns

Type | Description
--- | ---
ColorSpace | the color space

#### CreateDeviceCMYK()

Create a new DeviceCMYK ColorSpace object.

##### Declaration

    public static ColorSpace CreateDeviceCMYK()

##### Returns

Type | Description
--- | ---
ColorSpace | the color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### CreateDeviceGray()

Create a new DeviceGray ColorSpace object.

##### Declaration

    public static ColorSpace CreateDeviceGray()

##### Returns

Type | Description
--- | ---
ColorSpace | the color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### CreateDeviceRGB()

Create a new DeviceRGB ColorSpace object.

##### Declaration

    public static ColorSpace CreateDeviceRGB()

##### Returns

Type | Description
--- | ---
ColorSpace | the color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### CreateICCFromBuffer(SDFDoc, byte[])

Creates the icc from buffer.

##### Declaration

    public static ColorSpace CreateICCFromBuffer(SDFDoc doc, byte[] buffer)

##### Parameters

Type | Name | Description
--- | --- | ---
SDFDoc | doc | the doc
byte[] | buffer | the data

##### Returns

Type | Description
--- | ---
ColorSpace | the color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### CreateICCFromFile(SDFDoc, string)

Create a PDF 'ICCBased' color space given an ICC profile.

##### Declaration

    public static ColorSpace CreateICCFromFile(SDFDoc doc, string filepath)

##### Parameters

Type | Name | Description
--- | --- | ---
SDFDoc | doc | the doc
string | filepath | the filepath

##### Returns

Type | Description
--- | ---
ColorSpace | the color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### CreateICCFromFilter(SDFDoc, Filter)

Creates the icc from filter.

##### Declaration

    public static ColorSpace CreateICCFromFilter(SDFDoc doc, Filter filter)

##### Parameters

Type | Name | Description
--- | --- | ---
SDFDoc | doc | the doc
Filter | filter | the filter

##### Returns

Type | Description
--- | ---
ColorSpace | the color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### CreatePattern()

Create a new Pattern ColorSpace object.

##### Declaration

    public static ColorSpace CreatePattern()

##### Returns

Type | Description
--- | ---
ColorSpace | the color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### Destroy()

##### Declaration

    public void Destroy()

#### Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

##### Declaration

    public void Dispose()

#### Dispose(bool)

##### Declaration

    protected virtual void Dispose(bool disposing)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | disposing |

#### ~ColorSpace()

Releases all resources used by the ColorSpace

##### Declaration

    protected ~ColorSpace()

#### GetAlternateColorSpace()

Gets the alternate color space.

##### Declaration

    public virtual ColorSpace GetAlternateColorSpace()

##### Returns

Type | Description
--- | ---
ColorSpace | the alternate color space if it is available or NULL otherwise. Color spaces that include alternate color space are e_separation, e_device_n, and e_icc.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### GetBaseColorSpace()

Gets the base color space.

##### Declaration

    public virtual ColorSpace GetBaseColorSpace()

##### Returns

Type | Description
--- | ---
ColorSpace | the base color space if this is an e_indexed or e_pattern with associated base color space; NULL otherwise.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### GetComponentNum()

Gets the component num.

##### Declaration

    public virtual int GetComponentNum()

##### Returns

Type | Description
--- | ---
int | The number of components (tint components) used to represent color point for this color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### GetComponentNum(Type, Obj)

Gets the number of colorants (tint components) used to represent color point in this color space

##### Declaration

    public static int GetComponentNum(ColorSpace.Type cs_type, Obj cs)

##### Parameters

Type | Name | Description
--- | --- | ---
ColorSpace.Type | cs_type | `ColorSpace` type
Obj | cs | `ColorSpace` object

##### Returns

Type | Description
--- | ---
int | The number of colorants (tint components) used to represent color point in this color space

#### GetHighVal()

Gets the highest index for the color lookup table for Indexed color space.

##### Declaration

    public virtual int GetHighVal()

##### Returns

Type | Description
--- | ---
int | the highest index for the color lookup table for Indexed color space. Since the color table is indexed from zero to highval, the actual number of entries is highval + 1. For color spaces other than indexed the method returns 0.

##### Remarks

for color spaces other than Indexed this method throws an exception.

#### GetLookupTable()

Gets the lookup table.

##### Declaration

    public IntPtr GetLookupTable()

##### Returns

Type | Description
--- | ---
IntPtr | the color lookup table for Indexed color space. for color spaces other than indexed the method returns null.

##### Remarks

for color spaces other than Indexed this method throws an exception.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### GetSDFObj()

Gets the sDF obj.

##### Declaration

    public Obj GetSDFObj()

##### Returns

Type | Description
--- | ---
Obj | the underlying SDF/Cos object

#### GetTintFunction()

Gets the tint function.

##### Declaration

    public virtual Function GetTintFunction()

##### Returns

Type | Description
--- | ---
Function | the function that transforms tint values into color component values in the alternate color space.

##### Remarks

for color spaces other than Separation this method throws an exception.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### GetType()

Gets the type.

##### Declaration

    public virtual ColorSpace.Type GetType()

##### Returns

Type | Description
--- | ---
ColorSpace.Type | The type of this color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### GetType(Obj)

Gets the type.

##### Declaration

    public static ColorSpace.Type GetType(Obj cs)

##### Parameters

Type | Name | Description
--- | --- | ---
Obj | cs | Cos/SDF color space object.

##### Returns

Type | Description
--- | ---
ColorSpace.Type | The Type of a given SDF/Cos color space, or e_null for if SDF object is not a valid color space

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### InitColor(ColorPt)

Set color to the initial value used for this color space. The initial value depends on the color space (see 4.5.7 in PDF Ref. Manual).

##### Declaration

    public virtual void InitColor(ColorPt out_colorants)

##### Parameters

Type | Name | Description
--- | --- | ---
ColorPt | out_colorants | the out_colorants

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### InitComponentRanges(double[], double[])

Initialize default ranges for each color component in the color space. For example, default ranges for DeviceRGB are [0 1 0 1 0 1] but for Lab the default values might be [0 100 -100 100 -100 100].

##### Declaration

    public virtual void InitComponentRanges(double[] out_decode_low, double[] out_decode_range)

##### Parameters

Type | Name | Description
--- | --- | ---
double[] | out_decode_low | the out_decode_low
double[] | out_decode_range | the out_decode_range

##### Remarks

the size of resulting vectors will match the number of color components in this color space.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### IsAll()

Checks if is all.

##### Declaration

    public virtual bool IsAll()

##### Returns

Type | Description
--- | ---
bool | True if Separation color space contains the colorant All.

##### Remarks

for color spaces other than Separation this method throws an exception.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### IsNone()

Checks if is none.

##### Declaration

    public virtual bool IsNone()

##### Returns

Type | Description
--- | ---
bool | True if Separation or DeviceN color space contains None colorants. For DeviceN the function returns true only if component colorant names are all None.

##### Remarks

for color spaces other than Separation or DeviceN this method throws an exception.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

### Implements

IDisposable