public static void LoadSource(Stream str, UIImage img) { Wic.ImagingFactory fac = ThreadResource.GetWicFactory(); var d = new Wic.BitmapDecoder(fac, str, Wic.DecodeOptions.CacheOnLoad); if (img.data != null) { ClearResource(img); } img.data = str; img.Decoder = d; var frame = d.GetFrame(0); img.FrameDecoder = frame; var fconv = new Wic.FormatConverter(fac); fconv.Initialize(frame, Wic.PixelFormat.Format32bppPRGBA); img.Bitmap = fconv; img.Mapsize.Left = 0; img.Mapsize.Top = 0; img.Mapsize.Right = img.Bitmap.Size.Width; img.Mapsize.Bottom = img.Bitmap.Size.Height; lock (DX_Core.D2D) img.d2dmap = D2D1.Bitmap.FromWicBitmap(DX_Core.D2D.d2dContext, img.Bitmap); }
public static BitmapSource CreateWicBitmap(Stream str) { BitmapSource bs = new BitmapSource(); Wic.ImagingFactory fac = ThreadResource.GetWicFactory(); bs.Decoder = new Wic.BitmapDecoder(fac, str, Wic.DecodeOptions.CacheOnLoad); bs.FrameDecoder = bs.Decoder.GetFrame(0); bs.Converter = new Wic.FormatConverter(fac); bs.Converter.Initialize(bs.FrameDecoder, Wic.PixelFormat.Format32bppPRGBA); return(bs); }