39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Windows.Media.Imaging;
|
|
using JD.Core.Targa;
|
|
|
|
namespace JD.WPF.Extensions
|
|
{
|
|
public static class TargaImageExtensions
|
|
{
|
|
/// <summary>
|
|
/// Loads a Targa image file into a ImageBitmap object (WPF usage).
|
|
/// </summary>
|
|
/// <param name="sFileName">The Targa image filename</param>
|
|
/// <returns>A Bitmap object with the Targa image loaded into it.</returns>
|
|
public static BitmapImage LoadTargaImageAsBitmapImage(string sFileName)
|
|
{
|
|
BitmapImage bitmapImage;
|
|
using (TargaImage ti = new TargaImage(sFileName))
|
|
{
|
|
using (Bitmap bitmap = new Bitmap(ti.Image))
|
|
{
|
|
using (MemoryStream memory = new MemoryStream())
|
|
{
|
|
bitmap.Save(memory, ImageFormat.Png);
|
|
memory.Position = 0;
|
|
bitmapImage = new BitmapImage();
|
|
bitmapImage.BeginInit();
|
|
bitmapImage.StreamSource = memory;
|
|
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
|
bitmapImage.EndInit();
|
|
}
|
|
}
|
|
}
|
|
|
|
return bitmapImage;
|
|
}
|
|
}
|
|
}
|