private void button1_Click(object sender, EventArgs e) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "Images (*.jpg;*.png;*.bmp;*.dds)|*.jpg;*.png;*.bmp;*.dds"; dlg.Multiselect = false; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (Path.GetExtension(dlg.FileName).ToLower() == ".dds") { DDSImage i = new DDSImage(); if (!i.LoadFrom(dlg.FileName)) MessageBox.Show(i.GetLastError(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); else { if (i.Texture == null) MessageBox.Show("Invalid Image, Only 2D Textures Supported.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); else _original = i.BuildTextureFace(0); } } else { _original = new Bitmap(dlg.FileName); } UpdateRawImage(); } } }
private void button1_Click(object sender, EventArgs e) { if (pictureBox1.Image != null) pictureBox1.Image.Dispose(); pictureBox1.Image = null; pictureBox1.Size = new Size(10, 10); using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Multiselect = false; dlg.Filter = "DDS Files (*.dds)|*.dds"; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { _file = new DDSImage(); if (!_file.LoadFrom(dlg.FileName)) MessageBox.Show(_file.GetLastError()); else if(_file.Texture != null) { if (_file.Texture.Length <= 1) { trackBar1.Enabled = false; } else { trackBar1.Enabled = true; trackBar1.Maximum = _file.Texture.Length - 1; trackBar1.Minimum = 0; trackBar1.Value = 0; } Bitmap tmp = _file.BuildTextureFace(0); if (tmp != null) { pictureBox1.Image = tmp; pictureBox1.Size = pictureBox1.Image.Size; } comboBox1.SelectedIndex = 0; label2.Enabled = comboBox1.Enabled = false; label3.Enabled = trackBar2.Enabled = false; } else if (_file.CubeMapTexture != null) { int n = 1; DDSImageCubeMapFace f = (DDSImageCubeMapFace)0; int count = Enum.GetNames(f.GetType()).Length; for (int i = 0; i < count; i++) { int c = _file.CubeMapTexture[f].Mipmaps.Length; if (c > n) n = c; System.Diagnostics.Debug.Print(f.ToString()); f++; } if (n <= 1) { trackBar1.Enabled = false; } else { trackBar1.Enabled = true; trackBar1.Maximum = n - 1; trackBar1.Minimum = trackBar1.Value = 0; } Bitmap tmp = _file.BuildCubeMapFace((DDSImageCubeMapFace)0, 0); if (tmp != null) { pictureBox1.Image = tmp; pictureBox1.Size = pictureBox1.Image.Size; } label2.Enabled = comboBox1.Enabled = true; label3.Enabled = trackBar2.Enabled = false; } else if (_file.VolumeTexture != null) { int n = 1; for(int i = 0; i < _file.VolumeTexture.Mipmaps.Length;i++) { int c = _file.VolumeTexture.Mipmaps[i].Slices.Length; if (c > n) n = c; } if (_file.VolumeTexture.Mipmaps.Length <= 1) { trackBar1.Value=0; trackBar1.Enabled = false; } else { trackBar1.Maximum = _file.VolumeTexture.Mipmaps.Length; trackBar1.Value = trackBar1.Minimum = 0; } label3.Enabled = trackBar2.Enabled = true; if (n <= 1) { trackBar2.Enabled = false; } else { trackBar2.Maximum = n; trackBar2.Minimum = trackBar2.Value = 0; } label2.Enabled = comboBox1.Enabled = false; Bitmap tmp = _file.BuildVolumeTextureFace(0, 0); if (tmp != null) { pictureBox1.Image = tmp; pictureBox1.Size = pictureBox1.Image.Size; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); pictureBox1.Image = null; pictureBox1.Size = new Size(10, 10); } } } }