Exemple #1
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);
        }
Exemple #2
0
        private IReadOnlyList <WicPixelFormat> GetPixelFormatsList()
        {
            var list = new List <WicPixelFormat>();

            foreach (Guid pf in PixelFormats)
            {
                var format = WicPixelFormat.FromClsid(pf);
                if (format != null)
                {
                    list.Add(format);
                }
            }

            list.Sort();
            return(list);
        }
Exemple #3
0
        public void ConvertTo(Guid pixelFormat, WICBitmapDitherType ditherType = WICBitmapDitherType.WICBitmapDitherTypeNone, WicPalette palette = null, double alphaThresholdPercent = 0, WICBitmapPaletteType paletteTranslate = WICBitmapPaletteType.WICBitmapPaletteTypeCustom)
        {
            if (WicPixelFormat == null)
            {
                throw new InvalidOperationException();
            }

            var cvt = WicPixelFormat.GetPixelFormatConvertersTo(pixelFormat).FirstOrDefault();

            if (cvt == null)
            {
                throw new InvalidOperationException();
            }

            var converter = cvt.Convert(this, pixelFormat, ditherType, palette, alphaThresholdPercent, paletteTranslate);

            _comObject?.Dispose();
            _comObject = converter;
        }