TiffImage

TiffImage class

Process Tagged Image File Format (TIFF) raster images with our API, offering comprehensive support for various resolutions and advanced editing capabilities like EXIF data manipulation and alpha channels. Normalize angles for scanned images, resize, transform to grayscale, and apply filters, gamma corrections and image parameters adjustments with ease. Seamlessly handle multi-frame TIFF files, create graphics paths, add shapes, and effortlessly save images to different formats.

public class TiffImage : RasterCachedMultipageImage, IMultipageImageExt

Constructors

NameDescription
TiffImage(TiffFrame)Initialize a new object of the TiffImage class, specifying the frame parameter. This constructor facilitates the creation of a TiffImage instance, allowing developers to specify the frame to be loaded or processed, streamlining Tiff image handling tasks within their applications.
TiffImage(TiffFrame[])Create a new instance of the TiffImage class, providing a list of frames as a parameter. This constructor enables the initialization of a TiffImage object with multiple frames, facilitating efficient handling and processing of TIFF image sequences within software applications.

Properties

NameDescription
ActiveFrame { get; set; }Manage the active frame seamlessly, facilitating dynamic navigation and manipulation within the designated context. Empower your application to interact efficiently with multimedia content, enhancing user engagement and productivity.
AutoAdjustPalette { get; set; }Gets or sets a value indicating whether automatic adjust palette.
override BackgroundColor { get; set; }Gets or sets a value for the background color.
override BitsPerPixel { get; }Gets the image bits per pixel count.
Bounds { get; }Gets the image bounds.
BufferSizeHint { get; set; }Gets or sets the buffer size hint which is defined max allowed size for all internal buffers.
ByteOrder { get; set; }Toggle the byte order for TIFF files seamlessly, ensuring precise control over data interpretation. Empower your applications with the flexibility to adapt to diverse file specifications, enhancing compatibility and efficiency in data processing.
Container { get; }Gets the Image container.
DataStreamContainer { get; }Gets the object’s data stream.
Disposed { get; }Gets a value indicating whether this instance is disposed.
ExifData { get; set; }Access or modify EXIF data associated with the active frame seamlessly, empowering precise control over image metadata. Enhance your application’s capabilities by integrating this feature, ensuring accurate preservation and customization of essential image information.
override FileFormat { get; }Retrieve the file format value associated with the image. This property serves as a critical aspect of image metadata retrieval, allowing software applications to identify and interpret the format of the image data efficiently.
Frames { get; }Retrieve an array of TiffFrame instances, enabling comprehensive access and manipulation of individual frames within the TIFF image. Harness the power of this array to streamline image processing workflows, ensuring precise control and optimization of visual content.
override HasAlpha { get; }Determine whether the image has an alpha channel, providing crucial information for rendering and compositing operations. Integrate this feature to optimize visual processing workflows, ensuring accurate representation and manipulation of transparent elements.
virtual HasBackgroundColor { get; set; }Gets or sets a value indicating whether image has background color.
override HasTransparentColor { get; }Gets a value indicating whether image has transparent color.
override Height { get; }Gets the image height.
override HorizontalResolution { get; set; }Retrieve the horizontal resolution of the specified Image in pixels per inch, facilitating precise adjustment and rendering capabilities. Access essential image metadata effortlessly, empowering streamlined image processing workflows for enhanced user experiences.
override ImageOpacity { get; }Gets opacity of this image.
InterruptMonitor { get; set; }Gets or sets the interrupt monitor.
override IsCached { get; }Gets a value indicating whether image data is cached currently.
IsRawDataAvailable { get; }Gets a value indicating whether raw data loading is available.
override PageCount { get; }Retrieve the total count of pages within the specified document, facilitating efficient navigation and management of multi-page content. Incorporate this functionality to enhance user experience, enabling seamless access to comprehensive document structures.
virtual PageExportingAction { get; set; }Gets or sets the page exporting action. Please note that setting this method will automatically release page resources after it is executed. It will be executed just before each page is saved.
override Pages { get; }Access the pages of the document seamlessly, enabling dynamic navigation and manipulation within the content structure. Empower your application with efficient access to individual pages, facilitating streamlined document processing and enhanced user interaction.
Palette { get; set; }Gets or sets the color palette. The color palette is not used when pixels are represented directly.
override PremultiplyComponents { get; set; }Indicate if components necessitate premultiplication, ensuring efficient handling of visual elements. Enhance rendering processes by toggling this property, streamlining graphic workflows for optimized performance.
RawCustomColorConverter { get; set; }Gets or sets the custom color converter
virtual RawDataFormat { get; }Gets the raw data format.
RawDataSettings { get; }Gets the current raw data settings. Note when using these settings the data loads without conversion.
RawFallbackIndex { get; set; }Gets or sets the fallback index to use when palette index is out of bounds
RawIndexedColorConverter { get; set; }Gets or sets the indexed color converter
virtual RawLineSize { get; }Gets the raw line size in bytes.
Size { get; }Gets the image size.
virtual TransparentColor { get; set; }Gets the image transparent color.
virtual UpdateXmpData { get; set; }Gets or sets a value indicating whether to update the XMP metadata.
override UsePalette { get; }Gets a value indicating whether the image palette is used.
virtual UseRawData { get; set; }Gets or sets a value indicating whether to use raw data loading when the raw data loading is available.
override VerticalResolution { get; set; }Access the vertical resolution of the designated Image in pixels per inch, enabling precise adjustments and rendering optimizations. Utilize essential image data effortlessly to streamline image processing workflows, ensuring superior quality and performance in your applications.
override Width { get; }Gets the image width.
override XmpData { get; set; }Gets or sets XMP data from frame.

Methods

NameDescription
Add(TiffImage)Add the frames from the specified image seamlessly into the current frame, consolidating their content and enhancing compositional flexibility. Integrate this method to streamline frame management and manipulation within your application, facilitating efficient handling of multi-frame images.
AddFrame(TiffFrame)Incorporate the specified frame seamlessly into the image, expanding its content and versatility. Utilize this method to enhance image composition and management, empowering efficient handling of multi-frame images within your application.
AddFrames(TiffFrame[])Integrate the array of frames seamlessly into the image, enriching its content and versatility. Utilize this method to enhance image composition and management, enabling efficient handling of multi-frame images within your application.
virtual AddPage(RasterImage)Incorporate a new page into the existing image seamlessly, expanding its content and versatility. Utilize this method to enhance document composition and management, empowering efficient handling of multi-page images within your application.
override AdjustBrightness(int)Implement brightness adjustment for the image, allowing the modification of overall luminance levels. Incorporate this method into your image processing workflow to enhance visibility and improve the visual quality of images within your application.
override AdjustContrast(float)Enhance the contrast of the Image instance, amplifying the differences between its light and dark areas. Integrate this functionality to improve the visual clarity and overall quality of the image within your application.
override AdjustGamma(float)Apply gamma correction to the image, adjusting pixel intensities to achieve desired color balance. Incorporate this method into your image processing workflow to enhance visual quality and improve the accuracy of subsequent analysis or display tasks within your application.
override AdjustGamma(float, float, float)Perform gamma correction on the image using individual coefficients for red, green, and blue channels, allowing for fine-tuned adjustments of color balance and contrast. Integrate this method into your image processing pipeline to achieve precise control over color rendering and enhance visual fidelity within your application.
AlignResolutions()Implement the AlignResolutions helper method to synchronize horizontal and vertical resolutions, ensuring uniformity in image dimensions. This functionality facilitates streamlined image processing workflows by harmonizing resolution parameters, optimizing visual quality and consistency across various platforms and devices.
override BinarizeBradley(double)Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
override BinarizeBradley(double, int)Implement binarization on the image employing Bradley’s adaptive thresholding algorithm with integral image thresholding. This approach dynamically computes local thresholds based on the image’s neighborhood, enhancing adaptability to varying lighting conditions and ensuring robust segmentation for subsequent processing tasks within your application.
override BinarizeFixed(byte)Apply binarization to the image using a predefined threshold, converting it into a binary image with distinct foreground and background regions. Incorporate this method into your image processing workflow to facilitate segmentation and feature extraction tasks, enhancing the accuracy and efficiency of image analysis within your application.
override BinarizeOtsu()Utilize Otsu thresholding to perform binarization on the image, automatically determining the optimal threshold value based on the image’s histogram. Integrate this method into your image processing workflow to achieve effective segmentation and feature extraction, enhancing the accuracy and reliability of image analysis tasks within your application.
Blend(Point, RasterImage, byte)Blends this image instance with the overlay image.
override Blend(Point, RasterImage, Rectangle, byte)Blends this image instance with the overlay image.
override CacheData()Caches the data private.
CanSave(ImageOptionsBase)Determines whether image can be saved to the specified file format represented by the passed save options.
override Crop(Rectangle)Crop the image using a specified rectangular region, allowing precise selection of desired content. Integrate this method into your image processing workflow to efficiently remove unwanted areas and focus on essential details, enhancing the overall clarity and composition of the image.
override Crop(int, int, int, int)Perform cropping on the image by specifying shifts in the left, right, top, and bottom directions. This method enables precise selection of the desired portion of the image, facilitating efficient removal of unwanted areas and focusing on essential content. Integrate this functionality into your image processing pipeline to enhance clarity and composition as needed within your application.
Dispose()Disposes the current instance.
Dither(DitheringMethod, int)Performs dithering on the current image.
override Dither(DitheringMethod, int, IColorPalette)Execute dithering on the current image to enhance its visual quality and reduce color banding artifacts. Integrate this method into your image processing workflow to ensure smoother transitions between colors, resulting in improved overall image appearance and clarity.
override Filter(Rectangle, FilterOptionsBase)Filter the content within the specified rectangle, applying a designated image processing filter to enhance or modify the selected region. Integrate this method into your image manipulation workflow to achieve targeted enhancements or transformations within your application.
GetArgb32Pixel(int, int)Gets an image 32-bit ARGB pixel.
GetDefaultArgb32Pixels(Rectangle)Gets the default 32-bit ARGB pixels array.
virtual GetDefaultOptions(object[])Gets the default options.
GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader)Gets the default pixels array using partial pixel loader.
GetDefaultRawData(Rectangle, RawDataSettings)Gets the default raw data array.
GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings)Gets the default raw data array using partial pixel loader.
virtual GetModifyDate(bool)Gets the date and time the resource image was last modified.
override GetOriginalOptions()Retrieve options derived from the original file settings, facilitating seamless preservation of key parameters such as bit-depth and other essential attributes of the original image. Utilize this method to maintain fidelity and consistency in image processing tasks, ensuring optimal results without unnecessary alterations. For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the Save method, the output PNG image with 8-bit per pixel will be produced. To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass them to the Save method as the second parameter.
GetPixel(int, int)Gets an image pixel.
override GetSerializedStream(ImageOptionsBase, Rectangle, out int)Converts to aps.
GetSkewAngle()Gets the skew angle. This method is applicable to scanned text documents, to determine the skew angle when scanning.
override Grayscale()Convert the image to its grayscale representation, transforming it into a single-channel image where each pixel represents intensity. Integrate this method into your image processing pipeline to simplify analysis and enhance compatibility with grayscale-based algorithms, facilitating various computer vision and image analysis tasks within your application.
InsertFrame(int, TiffFrame)Insert the new frame at the specified index within the frame sequence, ensuring precise control over frame arrangement. Employ this method to manage frame sequences effectively, facilitating dynamic manipulation and organization of image content within your application.
LoadArgb32Pixels(Rectangle)Loads 32-bit ARGB pixels.
LoadArgb64Pixels(Rectangle)Loads 64-bit ARGB pixels.
LoadCmyk32Pixels(Rectangle)Loads pixels in CMYK format.
LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader)Loads 32-bit ARGB pixels partially by packs.
LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader)Loads 64-bit ARGB pixels partially by packs.
LoadPartialPixels(Rectangle, IPartialPixelLoader)Loads pixels partially by packs.
LoadPixels(Rectangle)Loads pixels.
LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader)Loads raw data.
LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader)Loads raw data.
NormalizeAngle()Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle and Rotate methods.
override NormalizeAngle(bool, Color)Utilize the NormalizeAngle method specifically designed for scanned text documents to rectify skewed scans, ensuring accurate alignment. Seamlessly integrate this functionality into your text processing workflows to enhance document readability and quality, improving overall efficiency in text recognition and analysis tasks. This method uses GetSkewAngle and Rotate methods.
ReadArgb32ScanLine(int)Reads the whole scan line by the specified scan line index.
ReadScanLine(int)Reads the whole scan line by the specified scan line index.
RemoveFrame(int)Effortlessly eliminate the frame identified by its index from the image sequence, streamlining frame management within your application. Integrate this functionality to enhance efficiency and precision in frame manipulation, facilitating seamless organization and presentation of image content.
RemoveFrame(TiffFrame)Efficiently remove the specified frame from the image sequence, facilitating streamlined frame management within your application. Integrate this functionality to enhance precision and flexibility in frame manipulation, ensuring seamless organization and presentation of image content.
ReplaceColor(Color, byte, Color)Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
override ReplaceColor(int, byte, int)Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
ReplaceFrame(int, TiffFrame)Substitute the frame at the designated position with another frame seamlessly, facilitating dynamic frame management within the image sequence. Integrate this method to enhance flexibility and precision in frame manipulation, ensuring optimal organization and presentation of image content within your application.
ReplaceNonTransparentColors(Color)Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.
override ReplaceNonTransparentColors(int)Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.
Resize(int, int)Resizes the image. The default NearestNeighbourResample is used.
override Resize(int, int, ImageResizeSettings)Adjust the size of the image based on specified settings, allowing for precise control over dimensions, aspect ratio, and scaling behavior. Integrate this method into your image processing workflow to achieve customized resizing operations tailored to the specific requirements of your application.
override Resize(int, int, ResizeType)Resize the image according to a specified resizing type, facilitating flexible adjustment of image dimensions while preserving aspect ratio or applying specific scaling algorithms. Incorporate this method into your image processing workflow to achieve precise control over resizing operations within your application.
ResizeHeightProportionally(int)Resizes the height proportionally. The default NearestNeighbourResample is used.
virtual ResizeHeightProportionally(int, ImageResizeSettings)Resizes the height proportionally.
override ResizeHeightProportionally(int, ResizeType)Conduct a proportional adjustment of the image’s height, preserving its aspect ratio for consistent visual integrity. Employ this method to dynamically resize images within your application, ensuring optimal display across diverse platforms and devices without compromising content quality.
ResizeProportional(int, int, ResizeType)Conduct a proportional resize operation on the image, preserving its aspect ratio while adjusting its dimensions. Employ this method to dynamically scale images within your application, ensuring consistent visual representation of content integrity. The proportional resize will resize each frame according to the ratio of newWidth/width and newHeight/height.
ResizeWidthProportionally(int)Resizes the width proportionally. The default NearestNeighbourResample is used.
virtual ResizeWidthProportionally(int, ImageResizeSettings)Resizes the width proportionally.
override ResizeWidthProportionally(int, ResizeType)Adjust the width of the image while maintaining its aspect ratio, ensuring proportional resizing for optimal visual presentation. Utilize this method to dynamically scale images within your application, facilitating consistent and aesthetically pleasing rendering across various display contexts.
virtual Rotate(float)Rotate image around the center.
override Rotate(float, bool, Color)Rotate the image around its center point by a specified angle, enabling precise orientation adjustments. Incorporate this functionality into your image processing pipeline to facilitate accurate transformations, ensuring optimal alignment and presentation of visual content within your application.
override RotateFlip(RotateFlipType)Perform rotation, flipping, or a combination of both operations exclusively on the active frame. This method allows precise manipulation of individual frames within the image sequence, enhancing flexibility in image editing and composition within your application.
Save()Saves the image data to the underlying stream.
Save(Stream)Saves the object’s data to the specified stream.
override Save(string)Saves the image to the specified file location.
Save(Stream, ImageOptionsBase)Saves the image’s data to the specified stream in the specified file format according to save options.
virtual Save(string, bool)Saves the object’s data to the specified file location.
virtual Save(string, ImageOptionsBase)Saves the object’s data to the specified file location in the specified file format according to save options.
override Save(Stream, ImageOptionsBase, Rectangle)Saves the image’s data to the specified stream in the specified file format according to save options.
virtual Save(string, ImageOptionsBase, Rectangle)Saves the object’s data to the specified file location in the specified file format according to save options.
SaveArgb32Pixels(Rectangle, int[])Saves the 32-bit ARGB pixels.
SaveCmyk32Pixels(Rectangle, int[])Saves the pixels.
SavePixels(Rectangle, Color[])Saves the pixels.
SaveRawData(byte[], int, Rectangle, RawDataSettings)Saves the raw data.
SetArgb32Pixel(int, int, int)Sets an image 32-bit ARGB pixel for the specified position.
override SetPalette(IColorPalette, bool)Sets the image palette.
SetPixel(int, int, Color)Sets an image pixel for the specified position.
override SetResolution(double, double)Establishes the resolution for the specified RasterImage, enabling precise control over image rendering and display properties. Integrate this functionality to optimize visual output and ensure compatibility with diverse output devices and platforms, enhancing the overall user experience.
virtual ToBitmap()Converts raster image to the bitmap. This method is not supported in versions from .Net7.0 and higher
WriteArgb32ScanLine(int, int[])Writes the whole scan line to the specified scan line index.
WriteScanLine(int, Color[])Writes the whole scan line to the specified scan line index.

Examples

Create Graphics Path from Path Resources in TIFF image.

[C#]

using (var image = (TiffImage)Image.Load("Bottle.tif"))
{
    // Create the GraphicsPath using PathResources from TIFF image
    var graphicsPath = PathResourceConverter.ToGraphicsPath(image.ActiveFrame.PathResources.ToArray(), image.ActiveFrame.Size);
    var graphics = new Graphics(image);

    // Draw red line and save the image
    graphics.DrawPath(new Pen(Color.Red, 10), graphicsPath);
    image.Save("BottleWithRedBorder.tif");
}

Create Path Resources using Graphics Path.

[C#]

static void Main(string[] args)
{
    using (var image = (TiffImage)Image.Load("Bottle.tif"))
    {
        // Create rectangular Figure for GraphicsPath
        var figure = new Figure();
        figure.AddShape(CreateBezierShape(100f, 100f, 500f, 100f, 500f, 1000f, 100f, 1000f));

        // Create GraphicsPath using our Figure
        var graphicsPath = new GraphicsPath();
        graphicsPath.AddFigure(figure);

        // Set PathResources using GraphicsPath
        var pathResouze = PathResourceConverter.FromGraphicsPath(graphicsPath, image.Size);
        image.ActiveFrame.PathResources = new List<PathResource>(pathResouze);

        // Save the image
        image.Save("BottleWithRectanglePath.tif");
    }
}

private static BezierShape CreateBezierShape(params float[] coordinates)
{
    var bezierPoints = CoordinatesToBezierPoints(coordinates).ToArray();
    return new BezierShape(bezierPoints, true);
}

private static IEnumerable<PointF> CoordinatesToBezierPoints(float[] coordinates)
{
    for (var coordinateIndex = 0; coordinateIndex < coordinates.Length; coordinateIndex += 2)
        for (var index = 0; index < 3; index++)
            yield return new PointF(coordinates[coordinateIndex], coordinates[coordinateIndex + 1]);
}

See Also