Esempio n. 1
0
        /// <summary>
        /// Creates a new collection of <see cref="HeifImage"/> from the specified data.
        /// </summary>
        /// <param name="input">The data to load the image from.</param>
        /// <returns>A new <see cref="HeifImage"/> instance.</returns>
        public static IHeifImageCollection DecodeCollection(byte[] input)
        {
            var result = new HeifImageCollection();

            HeifImageHandle?handle = null;

            try
            {
                using (var context = new HeifContext(input))
                {
                    foreach (var imageId in context.GetImageIds())
                    {
                        handle = new HeifImageHandle(context, imageId);

                        result.Add(new HeifImage(context, handle));
                    }
                }
            }
            catch
            {
                foreach (var image in result)
                {
                    image.Dispose();
                }

                handle?.Dispose();

                throw;
            }

            return(result);
        }
Esempio n. 2
0
        private HeifImage(HeifContext context, HeifImageHandle handle)
        {
            this.context        = context;
            this.handle         = handle;
            this.nativeInstance = new NativeHeifImage(handle);

            this.Metadata = new HeifMetadata(this.nativeInstance.Width, this.nativeInstance.Height);
        }
Esempio n. 3
0
        internal static IntPtr GetInstance(HeifImageHandle handle)
        {
            if (handle == null)
            {
                return(IntPtr.Zero);
            }

            return(handle.nativeInstance.Instance);
        }
Esempio n. 4
0
 /// <summary>
 /// Creates a new <see cref="HeifMetadata"/> from the specified data.
 /// </summary>
 /// <param name="input">The data to load the metadata from.</param>
 /// <returns>A new <see cref="HeifMetadata"/>.</returns>
 public static HeifMetadata GetMetadata(byte[] input)
 {
     using (var context = new HeifContext(input))
     {
         using (var handle = new HeifImageHandle(context))
         {
             return(handle.ToMetadata());
         }
     }
 }
Esempio n. 5
0
            public NativeHeifImage(HeifImageHandle handle)
            {
                var instance = NativeMethods.HeifImage_Create(HeifImageHandle.GetInstance(handle));

                if (instance == IntPtr.Zero)
                {
                    throw new HeifException("Unable to decode heif image.");
                }

                this.Instance = instance;
            }
Esempio n. 6
0
        /// <summary>
        /// Creates a new collection of <see cref="HeifMetadata"/> from the specified data.
        /// </summary>
        /// <param name="input">The data to load the metadata from.</param>
        /// <returns>A new <see cref="HeifMetadata"/>.</returns>
        public static IReadOnlyCollection <HeifMetadata> GetCollectionMetadata(byte[] input)
        {
            using (var context = new HeifContext(input))
            {
                var result = new List <HeifMetadata>();
                foreach (var imageId in context.GetImageIds())
                {
                    using (var handle = new HeifImageHandle(context, imageId))
                    {
                        result.Add(handle.ToMetadata());
                    }
                }

                return(result);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a new <see cref="HeifImage"/> from the specified data.
        /// </summary>
        /// <param name="input">The data to load the image from.</param>
        /// <returns>A new <see cref="HeifImage"/> instance.</returns>
        public static HeifImage Decode(byte[] input)
        {
            HeifContext?    context = null;
            HeifImageHandle?handle  = null;

            try
            {
                context = new HeifContext(input);
                handle  = new HeifImageHandle(context);

                return(new HeifImage(context, handle));
            }
            catch
            {
                handle?.Dispose();
                context?.Dispose();

                throw;
            }
        }