41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
|
using System;
|
||
|
using System.Drawing;
|
||
|
using System.IO;
|
||
|
using RecrownedGTK.AssetsSystem.Information;
|
||
|
using RecrownedGTK.Graphics;
|
||
|
|
||
|
namespace RecrownedGTK.AssetsSystem.Loaders {
|
||
|
public class TextureLoader : ILoader
|
||
|
{
|
||
|
public IInfo load(string path)
|
||
|
{
|
||
|
int width;
|
||
|
int height;
|
||
|
byte[] textureData = LoadPNG(path, out width, out height);
|
||
|
TextureInfo info = new TextureInfo(Path.GetFileName(path), width, height, textureData);
|
||
|
return info;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
///Load PNG data to this texture representation.
|
||
|
///
|
||
|
/// Decodes the PNG into a byte array to be stored.
|
||
|
/// </summary>
|
||
|
/// <param name="path">The path to the PNG file to be represented.</param>
|
||
|
/// <param name="width">Outputs the width of the PNG file.</param>
|
||
|
/// <param name="height">Outputs the height of the PNG file.</param>
|
||
|
/// <returns>A byte array representing the PNG.</returns>
|
||
|
private byte[] LoadPNG(string path, out int width, out int height) {
|
||
|
byte[] textureData = null;
|
||
|
using (FileStream file = new FileStream(path, FileMode.Open)) {
|
||
|
using (Bitmap bitmap = new Bitmap(file)) {
|
||
|
ImageConverter converter = new ImageConverter();
|
||
|
textureData = (byte[]) converter.ConvertTo(bitmap, typeof(byte[]));
|
||
|
width = bitmap.Width;
|
||
|
height = bitmap.Height;
|
||
|
}
|
||
|
}
|
||
|
return textureData;
|
||
|
}
|
||
|
}
|
||
|
}
|