zoukankan      html  css  js  c++  java
  • 各种图片格式转换

    1.WindowsForm中Image转换为System.Windows.Controls.Image转换

     /// <summary>
            /// 把DrawingImage转换为Controls使用的Iamge类
            /// </summary>
            /// <param name="gdiImg"></param>
            /// <returns></returns>
            private System.Windows.Controls.Image ConvertDrawingImageToWPFImage(System.Drawing.Image gdiImg)
            {


                System.Windows.Controls.Image img = new System.Windows.Controls.Image();

                //convert System.Drawing.Image to WPF image
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(gdiImg);
                IntPtr hBitmap = bmp.GetHbitmap();
                System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                img.Source = WpfBitmap;
                img.Width = 500;
                img.Height = 600;
                img.Stretch = System.Windows.Media.Stretch.Fill;
                return img;
            }

    2.Image转换为System.Windows.Media.ImageSource即WPF中使用的图片Source

       /// <summary>
            /// 把DrawingImage转换为System.Windows.Media.ImageSource WPF中使用的类中的Iamge类
            /// </summary>
            /// <param name="gdiImg"></param>
            /// <returns></returns>
            private System.Windows.Media.ImageSource ConvertDrawingImageToWPFImage(System.Drawing.Image gdiImg)
            {


                System.Windows.Controls.Image img = new System.Windows.Controls.Image();
                //convert System.Drawing.Image to WPF image
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(gdiImg);
                IntPtr hBitmap = bmp.GetHbitmap();
                return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            }

  • 相关阅读:
    2019年1月18日23:20:02 夜盘
    2019年1月16日22:50:28 白糖SR1905
    2018/12/20 20:52:42 螺纹钢PTA豆粕
    2018/12/19 20:55:58 螺纹钢豆粕PTA
    2018-12-18 豆粕
    2018-12-18 19:53 螺纹钢
    记录一下自己的跑步数据
    Xamarin.Lottie---UWP运行出错时的注意事项
    Hitting refresh on my career(译)----重新定义我的事业
    ChatKit for Xamarin.Android 绑定
  • 原文地址:https://www.cnblogs.com/haofaner/p/4028828.html
Copyright © 2011-2022 走看看