# PdfImage class

> A JPEG, PNG, GIF, BMP, TIFF or WebP image to draw with DrawImage. The image is written once per document however often it is drawn, and can be shared...

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

A JPEG, PNG, GIF, BMP, TIFF or WebP image to draw with
[DrawImage](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfgraphics/#PdfNetStack_Drawing_PdfGraphics_DrawImage_PdfNetStack_Drawing_PdfImage_System_Double_System_Double_System_Double_System_Double_). The image is
written once per document however often it is drawn, and can be shared between documents and
threads.

```csharp
public sealed class PdfImage
```

**Inheritance**

[object](https://learn.microsoft.com/dotnet/api/system.object) ← 
[PdfImage](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfimage/)

## Remarks

JPEGs are copied without recompression; EXIF orientation is honored, so photos stand upright.
PNGs keep their compressed data when that is possible (no alpha channel, not interlaced) and
otherwise are decoded once, their alpha becoming a soft mask. BMP, TIFF and WebP images are
decoded when loaded, except a TIFF page stored as one strip of fax or JPEG data, which is
copied. Embedded ICC profiles are kept when they describe the image's color space. Multi-page
TIFFs load one page at a time: see [GetPageCount](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfimage/#PdfNetStack_Drawing_PdfImage_GetPageCount_System_Byte___).
Decoding is bounded: images over 2^28 pixels are refused.

## Properties

### <a id="PdfNetStack_Drawing_PdfImage_Format"></a> Format

The source format.

```csharp
public PdfImageFormat Format { get; }
```

#### Property Value

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

### <a id="PdfNetStack_Drawing_PdfImage_HasTransparency"></a> HasTransparency

True when the image carries transparency: an alpha channel or a transparent color.

```csharp
public bool HasTransparency { get; }
```

#### Property Value

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

### <a id="PdfNetStack_Drawing_PdfImage_Height"></a> Height

Natural height in points as displayed, after EXIF orientation.

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

#### Property Value

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

### <a id="PdfNetStack_Drawing_PdfImage_HorizontalResolution"></a> HorizontalResolution

Horizontal pixels per inch, as the file records it, else 96.

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

#### Property Value

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

### <a id="PdfNetStack_Drawing_PdfImage_PixelHeight"></a> PixelHeight

Height of the stored image in pixels.

```csharp
public int PixelHeight { get; }
```

#### Property Value

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

### <a id="PdfNetStack_Drawing_PdfImage_PixelWidth"></a> PixelWidth

Width of the stored image in pixels.

```csharp
public int PixelWidth { get; }
```

#### Property Value

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

### <a id="PdfNetStack_Drawing_PdfImage_VerticalResolution"></a> VerticalResolution

Vertical pixels per inch, as the file records it, else 96.

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

#### Property Value

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

### <a id="PdfNetStack_Drawing_PdfImage_Width"></a> Width

Natural width in points as displayed, after EXIF orientation.

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

#### Property Value

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

## Methods

### <a id="PdfNetStack_Drawing_PdfImage_GetPageCount_System_String_"></a> GetPageCount\(string\)

The number of pages in a TIFF file; 1 for the other formats.

```csharp
public static int GetPageCount(string path)
```

#### Parameters

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

#### Returns

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

#### Exceptions

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

The data is not a supported image.

### <a id="PdfNetStack_Drawing_PdfImage_GetPageCount_System_Byte___"></a> GetPageCount\(byte\[\]\)

The number of pages in a TIFF image; 1 for the other formats. Animated GIF and WebP images
count as one page: their first frame is what loads.

```csharp
public static int GetPageCount(byte[] data)
```

#### Parameters

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

#### Returns

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

#### Exceptions

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

The data is not a supported image.

### <a id="PdfNetStack_Drawing_PdfImage_Load_System_String_"></a> Load\(string\)

Loads an image file: JPEG, PNG, GIF, BMP, TIFF (its first page) or WebP.

```csharp
public static PdfImage Load(string path)
```

#### Parameters

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

#### Returns

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

#### Exceptions

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

The data is not a supported image, or is damaged.

### <a id="PdfNetStack_Drawing_PdfImage_Load_System_IO_Stream_"></a> Load\(Stream\)

Loads an image from a stream, read to its end.

```csharp
public static PdfImage Load(Stream stream)
```

#### Parameters

`stream` [Stream](https://learn.microsoft.com/dotnet/api/system.io.stream)

#### Returns

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

#### Exceptions

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

The data is not a supported image, or is damaged.

### <a id="PdfNetStack_Drawing_PdfImage_Load_System_Byte___"></a> Load\(byte\[\]\)

Loads an image from its bytes. The array is used directly; do not change it afterwards.

```csharp
public static PdfImage Load(byte[] data)
```

#### Parameters

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

#### Returns

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

#### Exceptions

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

The data is not a supported image, or is damaged.

### <a id="PdfNetStack_Drawing_PdfImage_Load_System_String_System_Int32_"></a> Load\(string, int\)

Loads one page of a multi-page TIFF file. Other formats have only page 0.

```csharp
public static PdfImage Load(string path, int page)
```

#### Parameters

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

The file.

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

The page, from 0.

#### Returns

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

#### Exceptions

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

The data is not a supported image, or is damaged.

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

The image has no such page.

### <a id="PdfNetStack_Drawing_PdfImage_Load_System_Byte___System_Int32_"></a> Load\(byte\[\], int\)

Loads one page of a multi-page TIFF from its bytes. Other formats have only page 0.

```csharp
public static PdfImage Load(byte[] data, int page)
```

#### Parameters

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

The image file's bytes, used directly; do not change them afterwards.

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

The page, from 0.

#### Returns

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

#### Exceptions

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

The data is not a supported image, or is damaged.

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

The image has no such page.

### <a id="PdfNetStack_Drawing_PdfImage_Load_System_Byte___System_Int32_System_Int64_"></a> Load\(byte\[\], int, long\)

Loads one page of an image file from its bytes, refusing an image with more pixels than
<code class="paramref">maxPixels</code> before decoding it. Use it to bound the memory an untrusted
image can take: a decoded image holds up to four bytes per pixel.

```csharp
public static PdfImage Load(byte[] data, int page, long maxPixels)
```

#### Parameters

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

The image file's bytes, used directly; do not change them afterwards.

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

The page, from 0. Only TIFF files have more than page 0.

`maxPixels` [long](https://learn.microsoft.com/dotnet/api/system.int64)

Most pixels the image may have, from 1 to 2^28 (the default of the other overloads).

#### Returns

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

#### Exceptions

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

The data is not a supported image, is damaged, or has more than <code class="paramref">maxPixels</code> pixels.

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

The image has no such page, or <code class="paramref">maxPixels</code> is out of range.

## Used in

- [Compress PDF files in C# and .NET](https://www.jadev-corp.com/guides/compress-pdf/)
- [Add images to PDF in C# and .NET](https://www.jadev-corp.com/guides/images/)
- [Work with large PDF files in C#](https://www.jadev-corp.com/guides/large-files/)
- [Downsample images in a PDF in C#](https://www.jadev-corp.com/recipes/downsample-pdf-images/)
- [Reduce PDF size for email in C#](https://www.jadev-corp.com/recipes/reduce-pdf-size/)
- [Convert a TIFF to PDF in C#](https://www.jadev-corp.com/recipes/tiff-to-pdf/)

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