示例#1
0
        private static ID2D1Bitmap1 CreateD2dBitmap(
            IWICImagingFactory imagingFactory,
            string filename,
            ID2D1DeviceContext renderTarget)
        {
            using IWICBitmapDecoder decoder   = imagingFactory.CreateDecoderFromFileName(filename);
            using IWICBitmapFrameDecode frame = decoder.GetFrame(0);

            using IWICFormatConverter converter = imagingFactory.CreateFormatConverter();
            converter.Initialize(frame, PixelFormat.Format32bppPBGRA, BitmapDitherType.None, null, 0, BitmapPaletteType.Custom);
            return(renderTarget.CreateBitmapFromWicBitmap(converter, null));
        }
示例#2
0
        public static IComObject <T> CreateBitmapFromWicBitmap <T>(this ID2D1DeviceContext context, IWICBitmapSource source, D2D1_BITMAP_PROPERTIES1?properties = null) where T : ID2D1Bitmap1
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            using (var mem = properties.StructureToMemory())
            {
                context.CreateBitmapFromWicBitmap(source, mem.Pointer, out ID2D1Bitmap1 bmp).ThrowOnError();
                return(new ComObject <T>((T)bmp));
            }
        }