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

  • 相关阅读:
    springboot 梳理2--配置druid数据源
    springboot 梳理1--简单整合mybatis
    springmvc 梳理13--@RequestBody 和 @ResponseBody
    springmvc 梳理12--拦截器
    springmvc 梳理11--restful
    如何快速成长为技术大牛?阿里资深技术专家的总结亮了
    一句话+一张图理解——数据结构与算法
    .net 开发人员的瓶颈和职业发展
    c# 对象相等性和同一性
    c# 连等的写法都做了什么?
  • 原文地址:https://www.cnblogs.com/haofaner/p/4028828.html
Copyright © 2011-2022 走看看