protected override bool ProcessDecoder(MainForm form, IWICBitmapDecoder decoder, DataEntry[] de, object tag) { IWICBitmapDecoderInfo info = decoder.GetDecoderInfo(); try { Guid clsid; info.GetCLSID(out clsid); if (clsid != Parent.Clsid) { form.Add(this, Resources.IncorrectDecoderPickedUp, de, new DataEntry(Resources.Expected, Parent.Clsid), new DataEntry(Resources.Actual, clsid)); } else { Tag t = (Tag)tag; if (!t.SupportsMultiframe && decoder.GetFrameCount() > 1) { form.Add(this, Resources.DecoderDoesNotMultiframe, de, new DataEntry(Resources.FrameCount, decoder.GetFrameCount())); } } } finally { info.ReleaseComObject(); } return true; }
protected override bool ProcessDecoder(MainForm form, IWICBitmapDecoder decoder, DataEntry[] de, object tag) { CheckCopyPalette(form, de, decoder.CopyPalette); CheckGetColorContexts(form, de, decoder.GetColorContexts); if (decoder.GetFrameCount() == 0) { form.Add(this, Resources.FileNoFrames, de); } CheckGetBitmapSource(form, de, decoder.GetPreview, WinCodecError.WINCODEC_ERR_UNSUPPORTEDOPERATION); CheckGetBitmapSource(form, de, decoder.GetThumbnail, WinCodecError.WINCODEC_ERR_CODECNOTHUMBNAIL); return true; }
private void Initialize(IWICBitmapDecoder decoder) { Exception exception = null; IWICBitmapFrameDecode source = null; IWICFormatConverter converter = null; var factory = m_directCanvasFactory.WicImagingFactory; int hr = 0; hr = decoder.GetFrame(0, out source); if (hr != 0) { exception = new Exception(string.Format("Could not get the frame from the decoder.")); goto cleanup; } hr = factory.CreateFormatConverter(out converter); if (hr != 0) { exception = new Exception(string.Format("Could not create the format converter")); goto cleanup; } hr = converter.Initialize(source, ref WICFormats.WICPixelFormat32bppPBGRA, WICBitmapDitherType.WICBitmapDitherTypeNone, null, 0, WICBitmapPaletteType.WICBitmapPaletteTypeMedianCut); if (hr != 0) { exception = new Exception(string.Format("Could not initialize the converter")); goto cleanup; } bool canConvert; hr = converter.CanConvert(ref WICFormats.WICPixelFormat32bppPBGRA, ref WICFormats.WICPixelFormat32bppBGRA, out canConvert); if (hr != 0) { exception = new Exception(string.Format("Could not convert color formats")); goto cleanup; } hr = factory.CreateBitmapFromSource(converter, WICBitmapCreateCacheOption.WICBitmapCacheOnLoad, out m_internalBitmap); if (hr != 0) { exception = new Exception(string.Format("Could not create bitmap")); goto cleanup; } cleanup: if (converter != null) Marshal.ReleaseComObject(converter); if (source != null) Marshal.ReleaseComObject(source); if (decoder != null) Marshal.ReleaseComObject(decoder); if (exception != null) throw exception; else Initialize(); }