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;
}
///
///Load PNG data to this texture representation.
///
/// Decodes the PNG into a byte array to be stored.
///
/// The path to the PNG file to be represented.
/// Outputs the width of the PNG file.
/// Outputs the height of the PNG file.
/// A byte array representing the PNG.
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;
}
}
}