private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (currentPath == "") { return; } SetSaveFormat(); using (FileStream fs = new FileStream(currentPath, FileMode.Create)) currentFile.WriteFile(fs); using (MagickImage image = new MagickImage(currentFile.Data)) ReloadUI(image, currentFile.Format); }
private void importToolStripMenuItem1_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog { Filter = "All supported image formats (*.png;*.jpg;*.jpeg;*.dds)|*.png;*.jpg;*.jpeg;*.dds|PNG image (*.png)|*.png|JPEG image (*.jpeg;*.jpg)|*.jpeg;*.jpg|DDS texture (*.dds)|*.dds|All Files (*.*)|*.*", Multiselect = true }; if (open.ShowDialog() != DialogResult.OK) { return; } foreach (string filename in open.FileNames) { using (FileStream fs = new FileStream(filename, FileMode.Open)) { byte[] data = fs.ToBytes(); using (MagickImage image = new MagickImage(data)) { TextureFormat format; string internalPath = Path.GetFileName(filename); switch (Path.GetExtension(filename)) { case ".png": format = TextureFormat.ARGB32; break; case ".jpg": case ".jpeg": format = TextureFormat.RGB24; break; default: case ".dds": format = TextureFormat.DXT5; break; } TexFile file = new TexFile(internalPath, format, new Size(image.Width, image.Height)); file.Data = data; string outputFilename = Path.ChangeExtension(filename, ".tex"); using (var output = new FileStream(outputFilename, FileMode.Create)) file.WriteFile(output); } } } }