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

  • 相关阅读:
    Mybatis框架学习_6_mapper.xml 文件中的输入参数详解 (paraterType)
    Mybatis框架学习_5_自定义类型转换器
    Mybatis框架学习_4_属性文件、全局参数、别名
    Mybatis框架学习_3_基于约定或动态代理实现增删改查
    Mybatis框架学习_2_增删改查的简单实现
    Mybatis框架学习_1_简介以及入门示例
    Linux 系统下启动命名的书写过程
    spring-boot-Web学习2-模板引擎 Thymeleaf
    spring-boot-Web学习1-简介
    MacBook无法开机问题
  • 原文地址:https://www.cnblogs.com/haofaner/p/4028828.html
Copyright © 2011-2022 走看看