Пример #1
0
        public static void Encode(this IImageCodec imageCodec, IImage image, string filePath, IImageEncoderOptions options)
        {
            if (!imageCodec.IsSupportedFileFormat(filePath))
            {
                throw new FileFormatException(IO.Properties.ExceptionMessages.UnsupportedFileFormat);
            }

            using (FileStream fs = File.Open(filePath, FileMode.OpenOrCreate))
                imageCodec.Encode(image, fs, options);
        }
Пример #2
0
        public static IImage Decode(this IImageCodec imageCodec, string filePath)
        {
            if (!imageCodec.IsSupportedFileFormat(filePath))
            {
                throw new FileFormatException(IO.Properties.ExceptionMessages.UnsupportedFileFormat);
            }

            using (FileStream fs = File.OpenRead(filePath))
                return(imageCodec.Decode(fs));
        }
Пример #3
0
        private static IEnumerable <IImageCodec> GetImageCodecs(IFileFormat imageFormat)
        {
            List <IImageCodec> imageCodecs = new List <IImageCodec>();

            foreach (IImageCodec imageCodec in ImagingPluginLoader.GetImageCodecs())
            {
                IImageCodec nextImageCodec     = imageCodec;
                Type        nextImageCodecType = imageCodec.GetType();

                if (!(nextImageCodec is null) && !(imageFormat is null) && nextImageCodec.IsSupportedFileFormat(imageFormat) && nextImageCodecType.GetConstructor(new[] { typeof(IFileFormat) }) != null)
                {
                    nextImageCodec = (IImageCodec)Activator.CreateInstance(nextImageCodecType, new object[] { imageFormat });
                }

                imageCodecs.Add(nextImageCodec);
            }

            return(imageCodecs);
        }