Asset loading structure complete.
Loads information from loader. information creates useable. Minor folder restructuring. Untested.
This commit is contained in:
8
RecrownedGTK/AssetsSystem/Loaders/ILoader.cs
Normal file
8
RecrownedGTK/AssetsSystem/Loaders/ILoader.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
using RecrownedGTK.AssetsSystem.Information;
|
||||
namespace RecrownedGTK.AssetsSystem.Loaders {
|
||||
public interface ILoader
|
||||
{
|
||||
IInfo load(string path);
|
||||
}
|
||||
}
|
41
RecrownedGTK/AssetsSystem/Loaders/TextureLoader.cs
Normal file
41
RecrownedGTK/AssetsSystem/Loaders/TextureLoader.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user