Sprache: C#
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;
}
/// <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;
}
Alte URL:
/snippet/old-windows-forms-image-to-new-wpf-image/1324
nice idea. but how to use? Form1.Controls.Add() can not work. Can you make an example?
This example is not for Windows Forms. It’s for WPF: http://de.wikipedia.org/wiki/Windows_Presentation_Foundation