Feedback

C# - old Windows Forms Image to new WPF Image

Veröffentlicht von am 1/23/2010
(2 Bewertungen)
Convert a Fuckin old School System.Drawing.Image in a Beautiful new System.Windows.Controls.Image ;)

viel spaß damit ;)
 /// <summary>
        /// Convert a Fuckin old School System.Drawing.Image in a Beautiful
        /// new System.Windows.Controls.Image ;)
        /// </summary>
        /// <param name="Old_School_Image"></param>
        /// <returns></returns>
        public static System.Windows.Controls.Image WFormsImageToWPFImage(System.Drawing.Image Old_School_Image)
        {
            MemoryStream ms = new MemoryStream();
            Old_School_Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

            System.Windows.Media.Imaging.BitmapImage bImg = new System.Windows.Media.Imaging.BitmapImage();
            bImg.BeginInit();
            bImg.StreamSource = new MemoryStream(ms.ToArray());
            bImg.EndInit();

            System.Windows.Controls.Image WPFImage = new System.Windows.Controls.Image();
            WPFImage.Source = bImg;
            return WPFImage;
        }

Abgelegt unter Converter, Windows, Forms, Image, WPF.

2 Kommentare zum Snippet

jack schrieb am 2/24/2010:
nice idea. but how to use? Form1.Controls.Add() can not work. Can you make an example?
MikeElDios schrieb am 3/8/2010:
This example is not for Windows Forms. It's for WPF: http://de.wikipedia.org/wiki/Windows_Presentation_Foundation
 

Logge dich ein, um hier zu kommentieren!