ImageExtensionsSaveAsTiff(Image, Stream, Boolean) Method

Saves the specified image using the built-in TIFF encoder if available in the current operating system. Unlike the Save(Stream, ImageFormat) method, this one supports every PixelFormat.

Definition

Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 8.1.0
C#
public static void SaveAsTiff(
	this Image image,
	Stream stream,
	bool currentFrameOnly = true
)

Parameters

image  Image
The image to save. If contains multiple images, then the frames to be saved can be specified by the currentFrameOnly parameter.
stream  Stream
The stream to save the image into.
currentFrameOnly  Boolean  (Optional)
to save only the current frame of the specified image; to save all frames. The frames can represent pages, animation and resolution dimensions but in any case they will be saved as pages. This parameter is optional.
Default value: .

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Image. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

The image can only be saved if a built-in TIFF encoder is available in the current operating system.

If currentFrameOnly is and image is an icon, then images of the same resolution but lower color depth might be skipped.

Images with different PixelFormats are handled as follows (on Windows, unless specified otherwise):

Format1bppIndexed
If palette is black and white (in this order), then pixel format will be preserved. Otherwise, if the palette has no alpha entries, then before saving the image pixel format will be converted to Format4bppIndexed so the built-in encoder will preserve palette. If the palette contains alpha entries, then the pixel format of the reloaded image may turn Format32bppArgb.
Format4bppIndexed
If the palette has no alpha entries the pixel format is preserved when reloading the saved image. Otherwise, the pixel format of the reloaded image may turn Format32bppArgb
Format8bppIndexed
If the palette has no alpha entries the pixel format is preserved when reloading the saved image. Otherwise, the pixel format of the reloaded image may turn Format32bppArgb
Format16bppGrayScale
Before saving the image pixel format will be converted to Format8bppIndexed using a grayscale palette, because otherwise GDI+ would throw an exception.
Format16bppRgb555
On Windows, when reloading the saved image the pixel format will turn Format24bppRgb. On Linux, before saving the image pixel format will be converted to Format24bppRgb; otherwise, the saved image would be corrupted.
Format16bppRgb565
On Windows, when reloading the saved image the pixel format will turn Format24bppRgb. On Linux, before saving the image pixel format will be converted to Format24bppRgb; otherwise, the saved image would be corrupted.
Format16bppArgb1555
When reloading the saved image the pixel format will turn Format32bppArgb.
Format24bppRgb
When reloading the saved image the pixel format is preserved.
Format32bppRgb
When reloading the saved image the pixel format will turn Format32bppArgb.
Format32bppArgb
When reloading the saved image the pixel format is preserved.
Format32bppPArgb
On Windows, when reloading the saved image the pixel format will turn Format32bppArgb. On Linux, before saving the image pixel format will be converted to Format32bppArgb; otherwise, the alpha channel in the saved image would be corrupted.
Format48bppRgb
If the original image is already a 48 BPP TIFF image, then the pixel format is preserved (however, channels might be quantized using a 13 BPP resolution); otherwise, the image will be saved with Format24bppRgb pixel format.
Format64bppArgb
When reloading the saved image the pixel format will turn Format32bppArgb.
Format64bppPArgb
When reloading the saved image the pixel format will turn Format32bppArgb.

Exceptions

ArgumentNullExceptionimage or stream is .
InvalidOperationExceptionNo built-in encoder was found or the saving fails in the current operating system.

See Also