Пример #1
0
        public static BitmapSource ToBitmapSource(Bitmap bmp, APointF? size = null)
        {
            var ip = bmp.GetHbitmap();
            BitmapSource bs = null;
            try
            {
                bs = Imaging.CreateBitmapSourceFromHBitmap(ip,
                    IntPtr.Zero, Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());
            }
            finally
            {
                DeleteObject(ip);
            }

            if (size.HasValue)
            {
                return new TransformedBitmap(bs,
                    new ScaleTransform(size.Value.X / bs.PixelWidth,
                        size.Value.Y / bs.PixelHeight));
            }

            return bs;
        }
Пример #2
0
        public static BitmapSource ToBitmapSource(UBitmap uBitmap, APointF? size = null)
        {
            var bmp = DataHelper.ToBitmap(uBitmap);

            return ToBitmapSource(bmp, size);
        }