protected override bool ProcessEncoder(MainForm form, IWICBitmapEncoder encoder, object tag) { IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory(); IWICBitmap bitmap = factory.CreateBitmap(16, 16, Consts.GUID_WICPixelFormat32bppBGRA, WICBitmapCreateCacheOption.WICBitmapCacheOnLoad); IWICPalette palette = factory.CreatePalette(); palette.InitializePredefined(WICBitmapPaletteType.WICBitmapPaletteTypeFixedBW, false); IWICColorContext context = factory.CreateColorContext(); context.InitializeFromExifColorSpace(ExifColorSpace.sRGB); ComponentInfoHelper.CheckEquals <IWICBitmapEncoderInfo>(form, encoder.GetEncoderInfo, this, Extensions.CompareInfos); Check(form, encoder.SetPalette, palette); Check(form, encoder.SetThumbnail, bitmap); Check(form, encoder.SetPreview, bitmap); try { encoder.SetColorContexts(1, new IWICColorContext[] { context }); } catch (Exception e) { form.CheckHRESULT(this, WinCodecError.WINCODEC_ERR_UNSUPPORTEDOPERATION, e); } try { encoder.Commit(); form.Add(this, string.Format(CultureInfo.CurrentUICulture, Resources._0_ShouldFail, "IWICBitmapEncoder::Commit(...)"), new DataEntry(Resources.FrameCount, 0)); } catch (Exception e) { form.CheckHRESULT(this, WinCodecError.WINCODEC_ERR_FRAMEMISSING, e, new DataEntry(Resources.FrameCount, 0)); } palette.ReleaseComObject(); bitmap.ReleaseComObject(); factory.ReleaseComObject(); context.ReleaseComObject(); return(base.ProcessEncoder(form, encoder, tag)); }
protected override void RunOverride(MainForm form, object tag) { IWICImagingFactory factory = (IWICImagingFactory) new WICImagingFactory(); IWICBitmapDecoderInfo info = (IWICBitmapDecoderInfo)factory.CreateComponentInfo(Parent.Clsid); Guid cf; info.GetContainerFormat(out cf); IWICBitmapDecoder decoder = null; try { decoder = info.CreateInstance(); Guid containerFormat; try { decoder.GetContainerFormat(out containerFormat); if (containerFormat != cf) { form.Add(this, Resources.ContainerFormatsDoNotMatch, new DataEntry(Resources.Actual, cf), new DataEntry(Resources.Expected, containerFormat)); } } catch (Exception e) { form.Add(this, e.TargetSite.ToString(Resources._0_Failed), new DataEntry(e)); } ComponentInfoHelper.CheckEquals <IWICBitmapDecoderInfo>(form, decoder.GetDecoderInfo, this, Extensions.CompareInfos); } finally { factory.ReleaseComObject(); info.ReleaseComObject(); decoder.ReleaseComObject(); } base.RunOverride(form, tag); }