Sometimes you won't recreate some code pieces, you already created once.
But in some cases, you need to do some type conversations then. Heres a little example,
how you can translate your
৺System.Drawing.Bitmap to the new System.Windows.Media.Imaging.
৺BitmapImage type.
For faster
৺access, i put this lines of code into my own Imaging namespace. (Converter class)
For Converting a
৺System.Drawing.Bitmap to the System.Windows.Media.Imaging.
৺BitmapImage, i use a MemoryStream to cache the content information.
The function is static, so you dont need to create an instance of Converter first.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using System.IO;
namespace Dognet.Imaging
{
partial class Converter
{
/// <summary>
/// Converts a System.Drawing.Bitmap to a BitmapImage
/// </summary>
/// <param name="bitmap">the Bitmap</param>
/// <returns>the BitmapImage</returns>
public static BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
{
MemoryStream ms
= new MemoryStream
(); bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
BitmapImage bImg
= new System.
Windows.
Media.
Imaging.
BitmapImage();
bImg.BeginInit();
bImg.
StreamSource = new MemoryStream
(ms.
ToArray()); bImg.CreateOptions = BitmapCreateOptions.None;
bImg.CacheOption = BitmapCacheOption.Default;
bImg.EndInit();
ms.Close();
return bImg;
}
}
}