January 1, 2009

Converting a Winform Icon to a WPF Icon

private static ImageSource WinFormIconToWpfIcon(System.Drawing.Icon icon)
{
    System.IO.MemoryStream iconStream = new System.IO.MemoryStream();
    icon.Save(iconStream);
    iconStream.Seek(0, System.IO.SeekOrigin.Begin);
    IconBitmapDecoder ibd = new IconBitmapDecoder(iconStream, BitmapCreateOptions.None, BitmapCacheOption.Default);
    return ibd.Frames[0];
}

No comments: