• 各种图片格式转换


    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());
            }

  • 相关阅读:
    Redis5.x五种数据类型常见命令
    Redis5.x安装以及常见数据类型
    《Redis5.x入门教程》正式推出
    PPT制作套路指南
    如何更优雅地对接第三方API
    软件开发要质量还是要效率?
    前后端分离对于开发人员的挑战
    Spring中老生常谈的FactoryBean
    消费端如何保证消息队列MQ的有序消费
    《ElasticSearch6.x实战教程》之实战ELK日志分析系统、多数据源同步
  • 原文地址:https://www.cnblogs.com/haofaner/p/4028828.html
Copyright © 2020-2023  润新知