码迷,mamicode.com
首页 > 其他好文 > 详细

各种图片格式转换

时间:2014-10-16 16:44:12      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:io   使用   ar   for   sp   on   ef   bs   new   

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

各种图片格式转换

标签:io   使用   ar   for   sp   on   ef   bs   new   

原文地址:http://www.cnblogs.com/haofaner/p/4028828.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!