public static List<Texture> LoadFromFile(string rootPath ,string filePath) { ImageImporter importer = new ImageImporter(); ImageExporter exporter = new ImageExporter(); Image image; List<Texture> textures = new List<Texture>(); string[] fps = filePath.Split('*'); string fp; for (int i = 0; i < fps.Length; i++) { fp = rootPath + fps[i]; image = importer.LoadImage(fp); if (Path.GetExtension(fp) != ".tga" && Path.GetExtension(fp) != ".png") { if (!File.Exists(fp.Replace(Path.GetExtension(fp), ".tga"))) exporter.SaveImage(image, ImageType.Tga, fp.Replace(Path.GetExtension(fp), ".tga")); image = importer.LoadImage(fp.Replace(Path.GetExtension(fp), ".tga")); } //image.Bind(); //var info = DevIL.Unmanaged.IL.GetImageInfo(); //var bitmap = new System.Drawing.Bitmap(info.Width, info.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //var rect = new System.Drawing.Rectangle(0, 0, info.Width, info.Height); //var data = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //DevIL.Unmanaged.IL.CopyPixels(0, 0, 0, info.Width, info.Height, info.Depth, DataFormat.BGRA, DataType.UnsignedByte); //bitmap.UnlockBits(data); //var converter = new System.Drawing.ImageConverter(); //var test = converter.ConvertTo(bitmap, typeof(byte[])); //var raw = (byte[])converter.ConvertTo(bitmap, typeof(byte[])); textures.Add(new Texture(image, fp)); } return textures; }
public static Texture LoadFromFile(string filePath) { ImageImporter importer = new ImageImporter(); ImageExporter exporter = new ImageExporter(); Image image; image = importer.LoadImage(filePath); if (Path.GetExtension(filePath) != ".tga" && Path.GetExtension(filePath) != ".png") { if (!File.Exists(filePath.Replace(Path.GetExtension(filePath), ".tga"))) exporter.SaveImage(image, ImageType.Tga, filePath.Replace(Path.GetExtension(filePath), ".tga")); image = importer.LoadImage(filePath.Replace(Path.GetExtension(filePath), ".tga")); } //image.Bind(); //var info = DevIL.Unmanaged.IL.GetImageInfo(); //var bitmap = new System.Drawing.Bitmap(info.Width, info.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //var rect = new System.Drawing.Rectangle(0, 0, info.Width, info.Height); //var data = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //DevIL.Unmanaged.IL.CopyPixels(0, 0, 0, info.Width, info.Height, info.Depth, DataFormat.BGRA, DataType.UnsignedByte); //bitmap.UnlockBits(data); //var converter = new System.Drawing.ImageConverter(); //var test = converter.ConvertTo(bitmap, typeof(byte[])); //var raw = (byte[])converter.ConvertTo(bitmap, typeof(byte[])); return new Texture(image); }