public static WicImageContainer Load(Stream inStream) { var gch = GCHandle.Alloc(inStream); var sti = new IStreamImpl(gch); using var ccw = new SafeHandleReleaser(new SafeComCallable <IStreamImpl>(sti)); var dec = createDecoder((IStream *)ccw.Handle !.DangerousGetHandle()); return(WicImageContainer.Create(dec, ccw.Detach())); }
public WicImageEncoder(FileFormat format, Stream stm) { var fmt = formatMap.GetValueOrDefault(format, GUID_ContainerFormatPng); var gch = GCHandle.Alloc(stm); var sti = new IStreamImpl(gch); ccw = new SafeComCallable <IStreamImpl>(sti); using var encoder = default(ComPtr <IWICBitmapEncoder>); HRESULT.Check(Wic.Factory->CreateEncoder(&fmt, null, encoder.GetAddressOf())); HRESULT.Check(encoder.Get()->Initialize((IStream *)ccw.DangerousGetHandle(), WICBitmapEncoderCacheOption.WICBitmapEncoderNoCache)); WicEncoder = encoder.Detach(); }
private void btnCreateRead_Click(object sender, EventArgs e) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "All Files (*.*)|*.*"; dlg.ShowReadOnly = false; this.DialogResult = dlg.ShowDialog(); if (this.DialogResult == DialogResult.OK) { try { Stream = new IStreamImpl(dlg.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } Close(); }