# PdfColor struct

> A device color with an opacity. Components are 0 to 1. Opacity below 1 is written as a constant alpha graphics state.

Namespace: [PdfNetStack.Drawing](https://www.jadev-corp.com/api/pdfnetstack-drawing/)  
Assembly: PdfNetStack.dll  
Package: `PdfNetStack`

A device color with an opacity. Components are 0 to 1. Opacity below 1 is written as a
constant alpha graphics state.

```csharp
public readonly struct PdfColor : IEquatable<PdfColor>
```

**Implements**

[IEquatable&lt;PdfColor\>](https://learn.microsoft.com/dotnet/api/system.iequatable\-1)

## Properties

### <a id="PdfNetStack_Drawing_PdfColor_Alpha"></a> Alpha

Opacity, 0 transparent to 1 opaque.

```csharp
public double Alpha { get; }
```

#### Property Value

 [double](https://learn.microsoft.com/dotnet/api/system.double)

### <a id="PdfNetStack_Drawing_PdfColor_Black"></a> Black

Opaque black.

```csharp
public static PdfColor Black { get; }
```

#### Property Value

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

### <a id="PdfNetStack_Drawing_PdfColor_Space"></a> Space

The color model.

```csharp
public PdfColorSpace Space { get; }
```

#### Property Value

 [PdfColorSpace](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolorspace/)

### <a id="PdfNetStack_Drawing_PdfColor_Transparent"></a> Transparent

Fully transparent.

```csharp
public static PdfColor Transparent { get; }
```

#### Property Value

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

### <a id="PdfNetStack_Drawing_PdfColor_White"></a> White

Opaque white.

```csharp
public static PdfColor White { get; }
```

#### Property Value

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

## Methods

### <a id="PdfNetStack_Drawing_PdfColor_Cmyk_System_Double_System_Double_System_Double_System_Double_System_Double_"></a> Cmyk\(double, double, double, double, double\)

A CMYK color with components 0 to 1.

```csharp
public static PdfColor Cmyk(double cyan, double magenta, double yellow, double black, double alpha = 1)
```

#### Parameters

`cyan` [double](https://learn.microsoft.com/dotnet/api/system.double)

`magenta` [double](https://learn.microsoft.com/dotnet/api/system.double)

`yellow` [double](https://learn.microsoft.com/dotnet/api/system.double)

`black` [double](https://learn.microsoft.com/dotnet/api/system.double)

`alpha` [double](https://learn.microsoft.com/dotnet/api/system.double)

#### Returns

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

### <a id="PdfNetStack_Drawing_PdfColor_Components"></a> Components\(\)

The components in the order the color space defines: 1, 3 or 4 values.

```csharp
public double[] Components()
```

#### Returns

 [double](https://learn.microsoft.com/dotnet/api/system.double)\[\]

### <a id="PdfNetStack_Drawing_PdfColor_Equals_PdfNetStack_Drawing_PdfColor_"></a> Equals\(PdfColor\)

Indicates whether the current object is equal to another object of the same type.

```csharp
public bool Equals(PdfColor other)
```

#### Parameters

`other` [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

An object to compare with this object.

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

<a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">true</a> if the current object is equal to the <code class="paramref">other</code> parameter; otherwise, <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">false</a>.

### <a id="PdfNetStack_Drawing_PdfColor_Equals_System_Object_"></a> Equals\(object?\)

Indicates whether this instance and a specified object are equal.

```csharp
public override bool Equals(object? obj)
```

#### Parameters

`obj` [object](https://learn.microsoft.com/dotnet/api/system.object)?

The object to compare with the current instance.

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

<a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">true</a> if <code class="paramref">obj</code> and this instance are the same type and represent the same value; otherwise, <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">false</a>.

### <a id="PdfNetStack_Drawing_PdfColor_FromHex_System_String_"></a> FromHex\(string\)

Parses #RGB, #RGBA, #RRGGBB or #RRGGBBAA, with or without the hash.

```csharp
public static PdfColor FromHex(string hex)
```

#### Parameters

`hex` [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Returns

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

#### Exceptions

 [FormatException](https://learn.microsoft.com/dotnet/api/system.formatexception)

The text is not a hex color.

### <a id="PdfNetStack_Drawing_PdfColor_FromRgb_System_Byte_System_Byte_System_Byte_System_Double_"></a> FromRgb\(byte, byte, byte, double\)

An RGB color with components 0 to 255, as in CSS and most image tools.

```csharp
public static PdfColor FromRgb(byte red, byte green, byte blue, double alpha = 1)
```

#### Parameters

`red` [byte](https://learn.microsoft.com/dotnet/api/system.byte)

`green` [byte](https://learn.microsoft.com/dotnet/api/system.byte)

`blue` [byte](https://learn.microsoft.com/dotnet/api/system.byte)

`alpha` [double](https://learn.microsoft.com/dotnet/api/system.double)

#### Returns

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

### <a id="PdfNetStack_Drawing_PdfColor_GetHashCode"></a> GetHashCode\(\)

Returns the hash code for this instance.

```csharp
public override int GetHashCode()
```

#### Returns

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

A 32-bit signed integer that is the hash code for this instance.

### <a id="PdfNetStack_Drawing_PdfColor_Gray_System_Double_System_Double_"></a> Gray\(double, double\)

A gray level, 0 black to 1 white.

```csharp
public static PdfColor Gray(double level, double alpha = 1)
```

#### Parameters

`level` [double](https://learn.microsoft.com/dotnet/api/system.double)

`alpha` [double](https://learn.microsoft.com/dotnet/api/system.double)

#### Returns

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

### <a id="PdfNetStack_Drawing_PdfColor_Rgb_System_Double_System_Double_System_Double_System_Double_"></a> Rgb\(double, double, double, double\)

An RGB color with components 0 to 1.

```csharp
public static PdfColor Rgb(double red, double green, double blue, double alpha = 1)
```

#### Parameters

`red` [double](https://learn.microsoft.com/dotnet/api/system.double)

`green` [double](https://learn.microsoft.com/dotnet/api/system.double)

`blue` [double](https://learn.microsoft.com/dotnet/api/system.double)

`alpha` [double](https://learn.microsoft.com/dotnet/api/system.double)

#### Returns

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

### <a id="PdfNetStack_Drawing_PdfColor_ToRgb"></a> ToRgb\(\)

The color converted to RGB (CMYK by the naive formula, without a color profile).

```csharp
public PdfColor ToRgb()
```

#### Returns

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

### <a id="PdfNetStack_Drawing_PdfColor_ToString"></a> ToString\(\)

Returns the fully qualified type name of this instance.

```csharp
public override string ToString()
```

#### Returns

 [string](https://learn.microsoft.com/dotnet/api/system.string)

The fully qualified type name.

### <a id="PdfNetStack_Drawing_PdfColor_WithAlpha_System_Double_"></a> WithAlpha\(double\)

The same color with another opacity.

```csharp
public PdfColor WithAlpha(double alpha)
```

#### Parameters

`alpha` [double](https://learn.microsoft.com/dotnet/api/system.double)

#### Returns

 [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

## Operators

### <a id="PdfNetStack_Drawing_PdfColor_op_Equality_PdfNetStack_Drawing_PdfColor_PdfNetStack_Drawing_PdfColor_"></a> operator ==\(PdfColor, PdfColor\)

Equality.

```csharp
public static bool operator ==(PdfColor left, PdfColor right)
```

#### Parameters

`left` [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

`right` [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="PdfNetStack_Drawing_PdfColor_op_Inequality_PdfNetStack_Drawing_PdfColor_PdfNetStack_Drawing_PdfColor_"></a> operator \!=\(PdfColor, PdfColor\)

Inequality.

```csharp
public static bool operator !=(PdfColor left, PdfColor right)
```

#### Parameters

`left` [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

`right` [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

## Used in

- [PDF coordinates and units in PdfNetStack](https://www.jadev-corp.com/concepts/coordinates-and-units/)
- [Get started with PdfNetStack](https://www.jadev-corp.com/getting-started/)
- [PDF links and annotations in C# and .NET](https://www.jadev-corp.com/guides/annotations/)
- [Compress PDF files in C# and .NET](https://www.jadev-corp.com/guides/compress-pdf/)
- [Draw on PDF pages in C# and .NET](https://www.jadev-corp.com/guides/drawing/)
- [Extract text from PDF files in C#](https://www.jadev-corp.com/guides/extract-text/)
- [Fonts and text in PDF with C# and .NET](https://www.jadev-corp.com/guides/fonts-and-text/)
- [Fill and create PDF forms in C# and .NET](https://www.jadev-corp.com/guides/forms/)
- [Add images to PDF in C# and .NET](https://www.jadev-corp.com/guides/images/)
- [Create PDF/A files in C# and .NET](https://www.jadev-corp.com/guides/pdf-a/)
- [Add page numbers to a PDF in C#](https://www.jadev-corp.com/recipes/add-page-numbers/)
- [Add a signature field to a PDF in C#](https://www.jadev-corp.com/recipes/add-signature-field/)
- [Add a watermark to a PDF in C#](https://www.jadev-corp.com/recipes/add-watermark/)
- [Create a Factur-X invoice PDF in C#](https://www.jadev-corp.com/recipes/pdf-a-3-xml-attachment/)

Source: https://www.jadev-corp.com/pdfnetstack/api/pdfnetstack-drawing/pdfcolor/
