Esempio n. 1
0
        public void Save(string filePath,
                         Guid?encoderContainerFormat = null,
                         Guid?pixelFormat            = null,
                         WICBitmapEncoderCacheOption cacheOptions = WICBitmapEncoderCacheOption.WICBitmapEncoderNoCache,
                         IEnumerable <KeyValuePair <string, object> > encoderOptions = null,
                         IEnumerable <WicMetadataKeyValue> metadata = null,
                         WicPalette encoderPalette = null,
                         WicPalette framePalette   = null,
                         WICRect?sourceRectangle   = null)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            Guid format;

            if (!encoderContainerFormat.HasValue)
            {
                var encoder = WicEncoder.FromFileExtension(Path.GetExtension(filePath));
                if (encoder == null)
                {
                    throw new WicNetException("WIC0003: Cannot determine encoder from file path.");
                }

                format = encoder.ContainerFormat;
            }
            else
            {
                format = encoderContainerFormat.Value;
            }

            using (var file = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                Save(file, format, pixelFormat, cacheOptions, encoderOptions, metadata, encoderPalette, framePalette, sourceRectangle);
        }
Esempio n. 2
0
        private static Dictionary <Guid, WicImagingComponent> LoadAllComponents()
        {
            var dic = new Dictionary <Guid, WicImagingComponent>();

            WICImagingFactory.WithFactory(f =>
            {
                foreach (var component in f.EnumerateComponents(WICComponentType.WICAllComponents, WICComponentEnumerateOptions.WICComponentEnumerateDefault))
                {
                    component.Object.GetComponentType(out var type);
                    WicImagingComponent ic;
                    switch (type)
                    {
                    case WICComponentType.WICPixelFormat:
                        ic = new WicPixelFormat(component);
                        break;

                    case WICComponentType.WICEncoder:
                        ic = new WicEncoder(component);
                        break;

                    case WICComponentType.WICDecoder:
                        ic = new WicDecoder(component);
                        break;

                    case WICComponentType.WICPixelFormatConverter:
                        var converter = new WicPixelFormatConverter(component);
                        ic            = converter;
                        break;

                    case WICComponentType.WICMetadataReader:
                        var reader = new WicMetadataReader(component);
                        ic         = reader;
                        break;

                    case WICComponentType.WICMetadataWriter:
                        var writer = new WicMetadataWriter(component);
                        ic         = writer;
                        break;

                    default:
                        ic = new WicImagingComponent(component);
                        break;
                    }

                    dic.Add(ic.Clsid, ic);

                    //WicEncoder.CreateBuiltIn();
                    //WicDecoder.CreateBuiltIn();
                    component.Dispose();
                }
            });
            return(dic);
        }
Esempio n. 3
0
 // they are supposed to have the same container format
 public static WicDecoder FromEncoder(WicEncoder encoder) => encoder != null?FromContainerFormatGuid(encoder.ContainerFormat) : null;