public override Texture2DContent Import(string filename, ContentImporterContext context) { // Load Arena2Path.txt arena2Path = File.ReadAllText( Path.Combine(Path.GetDirectoryName(filename), Arena2PathTxt)); // Read input text string input = File.ReadAllText(filename); // Remove new lines input = input.Replace('\n', ' ').Trim(); input = input.Replace('\r', ' ').Trim(); // Get source information string[] lines = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string textureFilename = lines[0].Trim(); int record = Convert.ToInt32(lines[1].Trim()); int frame = Convert.ToInt32(lines[2].Trim()); // Get bitmap in RGBA format ImageFileReader fileReader = new ImageFileReader(arena2Path); DFImageFile imageFile = fileReader.LoadFile(textureFilename); DFBitmap dfBitmap = imageFile.GetBitmapFormat(record, frame, 0, DFBitmap.Formats.RGBA); // Set bitmap data BitmapContent bitmapContent = new PixelBitmapContent <Color>(dfBitmap.Width, dfBitmap.Height); bitmapContent.SetPixelData(dfBitmap.Data); Texture2DContent tc = new Texture2DContent(); tc.Faces[0] = bitmapContent; return(tc); }
private void ShowMeshTextures() { // Clear texture flow panel TexturesPanel.Controls.Clear(); // Get the mesh data DFMesh mesh = arch3dFile.GetMesh(MeshIndexTrackBar.Value); // Loop through all submeshes foreach (DFMesh.DFSubMesh sm in mesh.SubMeshes) { // Load texture file string FileName = TextureFile.IndexToFileName(sm.TextureArchive); MyImageFileReader.LoadFile(FileName); // Get texture file DFImageFile textureFile = MyImageFileReader.ImageFile; // Get managed bitmap Bitmap bm = textureFile.GetManagedBitmap(sm.TextureRecord, 0, true, false); // Create a new picture box PictureBox pb = new PictureBox(); pb.Width = bm.Width; pb.Height = bm.Height; pb.Image = bm; // Add picture box to flow panel TexturesPanel.Controls.Add(pb); } }
static void Main(string[] args) { // Specify Arena2 path of local Daggerfall installation string MyArena2Path = "C:\\dosgames\\DAGGER\\ARENA2"; // Instantiate ImageFileReader ImageFileReader MyImageFileReader = new ImageFileReader(MyArena2Path); // Set desired library type MyImageFileReader.LibraryType = LibraryTypes.Texture; // Load TEXTURE.285 file MyImageFileReader.LoadFile("TEXTURE.285"); // Output some information about this file Console.WriteLine("Image file {0} has {1} records", MyImageFileReader.FileName, MyImageFileReader.RecordCount); // Get image file to work with DFImageFile imageFile = MyImageFileReader.ImageFile; // Loop through all records for (int r = 0; r < imageFile.RecordCount; r++) { // Output some information about this record int frameCount = imageFile.GetFrameCount(r); Size sz = imageFile.GetSize(r); Console.WriteLine("Record {0} has {1} frames and is {2}x{3} pixels", r, frameCount, sz.Width, sz.Height); // Get first frame of record as a managed bitmap Bitmap managedBitmap = imageFile.GetManagedBitmap(r, 0, true, false); } }