Example #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);
        }
Example #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);
        }
Example #3
0
        internal static IntPtr GetInstance(HeifContext context)
        {
            if (context == null)
            {
                return(IntPtr.Zero);
            }

            return(context.nativeInstance.Instance);
        }
Example #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());
         }
     }
 }
Example #5
0
            public NativeHeifImageHandle(HeifContext context, uint imageId)
            {
                var instance = NativeMethods.HeifImageHandle_CreateById(HeifContext.GetInstance(context), imageId);

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

                this.Instance = instance;
            }
Example #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);
            }
        }
Example #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;
            }
        }
Example #8
0
 public HeifImageHandle(HeifContext context)
 {
     this.nativeInstance = new NativeHeifImageHandle(context);
 }
Example #9
0
 public HeifImageHandle(HeifContext context, uint imageId)
 {
     this.nativeInstance = new NativeHeifImageHandle(context, imageId);
     context.AddReference();
 }