Click or drag to resize

HeifDecoder Class

Decoder for HEIF files.
Inheritance Hierarchy
SystemObject
  Atalasoft.Imaging.CodecImageDecoder
    Atalasoft.Imaging.CodecMultiFramedImageDecoder
      Atalasoft.Imaging.CodecHeifDecoder

Namespace:  Atalasoft.Imaging.Codec
Assembly:  Atalasoft.dotImage.Heif (in Atalasoft.dotImage.Heif.dll) Version: 11.4.0.9.0.377 (.NET 4.5.2, x86)
Syntax
public class HeifDecoder : MultiFramedImageDecoder

The HeifDecoder type exposes the following members.

Constructors
  NameDescription
Public methodHeifDecoder
Initializes a new instance of HeifDecoder class.
Top
Properties
  NameDescription
Public propertySupportedImageType Obsolete.
Returns the ImageType that the implemented decoder class supports.
(Inherited from ImageDecoder.)
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetFrameCount
Returns the number of frames in the image
(Overrides MultiFramedImageDecoderGetFrameCount(Stream).)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetHeifDocument
Provides an access to HEIF files data.
Public methodGetImageInfo(Stream)
Retrieves information from an image stored in a file without decoding the image data.
(Overrides ImageDecoderGetImageInfo(Stream).)
Public methodGetImageInfo(Stream, Int32) (Overrides MultiFramedImageDecoderGetImageInfo(Stream, Int32).)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIsValidFormat
Checks the stream to determine if the image can be read by the decoder that derives this class.
(Overrides ImageDecoderIsValidFormat(Stream).)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRead(Stream, ProgressEventHandler)
Decode an image in a specified image Stream.
(Overrides ImageDecoderRead(Stream, ProgressEventHandler).)
Public methodRead(Stream, Int32, ProgressEventHandler)
Read a given frame in an encoded image using this decoder.
(Overrides MultiFramedImageDecoderRead(Stream, Int32, ProgressEventHandler).)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks
HeifDecoder allows to read master images from HEIF files the same way as other decoders provided by the SDK:
Using as regular decoder
var imagesCount = heifDecoder.GetFrameCount(stream);
for (int i = 0; i < imagesCount; i++)
{
    using (var atalaImage = heifDecoder.Read(stream, i, null))
    {
        // .. process image here
    }
}
or HEIF images can be loaded indirectly using AtalaImage class constructor:
Loading HEIF images indirectly
RegisteredDecoders.Decoders.Add(heifDecoder);

using (var atalaImage = new AtalaImage(stream))
{
    // .. process image here
}
In order to get access to auxiliary images, thumbnails, etc. GetHeifDocument(Stream, ProgressEventHandler) method should be used:
Getting additional info from HEIF
var heifDocument = heifDecoder.GetHeifDocument(stream, null);
foreach (var heifImage in heifDocument.HeifImages)
{
    // reading auxiliary images
    foreach (var auxiliaryImage in heifImage.AuxiliaryImages)
    {
        // process auxiliary image
    }

    // retrieve AtalaImage 
    var atalaImage = heifImage.GetImage();
}
The following sample illustrates how to print exif and XML metadata.
Print exif and XMP metadata
using (var document = heifDecoder.GetHeifDocument(stream, null))
{
    foreach (var heifImage in document.HeifImages)
    {
        foreach (var metadata in heifImage.Metadata)
        {
            if (metadata.Type.Equals("exif", StringComparison.CurrentCultureIgnoreCase))
            {
                var exifCollection = metadata.AsExifCollection();
                foreach (ExifTag exifTag in exifCollection)
                {
                    Console.WriteLine(exifTag.ToString());
                }
            } else if (metadata.Type.Equals("mime", StringComparison.CurrentCultureIgnoreCase) &&
                       metadata.ContentType.Equals("application/rdf+xml",
                           StringComparison.CurrentCultureIgnoreCase))
            {
                var doc = new XmlDocument();
                doc.LoadXml(System.Text.Encoding.UTF8.GetString(metadata.Data));

                StringWriter sw = new StringWriter();
                doc.Save(sw);

                Console.WriteLine(sw.ToString());
            }
        }
    }
}
See Also