private static void SaveTextureAsPNG(BMD.Texture currentTexture, String fileName) { Bitmap tex = new Bitmap((int)currentTexture.m_Width, (int)currentTexture.m_Height); for (int y = 0; y < (int)currentTexture.m_Height; y++) { for (int x = 0; x < (int)currentTexture.m_Width; x++) { tex.SetPixel(x, y, Color.FromArgb(currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 3], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 2], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 1], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4])); } } try { tex.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); } catch (Exception ex) { MessageBox.Show("An error occurred while trying to save texture " + currentTexture.m_TexName + ".\n\n " + ex.Message + "\n" + ex.Data + "\n" + ex.StackTrace + "\n" + ex.Source); } }
private void lbxTextures_SelectedIndexChanged(object sender, EventArgs e) { if (lbxTextures.SelectedIndex == -1 || lbxTextures.SelectedIndex >= lbxTextures.Items.Count) { return; } string texName = lbxTextures.Items[lbxTextures.SelectedIndex].ToString(); if (rbTexAllInBMD.Checked && m_Model.m_Textures.ContainsKey(texName)) { if (m_Model.m_Textures[texName].m_PalID >= 0 && m_Model.m_Textures[texName].m_PalID < lbxPalettes.Items.Count) { lbxPalettes.SelectedIndex = (int)m_Model.m_Textures[texName].m_PalID; } } if (rbTexAllInBMD.Checked && lbxPalettes.SelectedIndex != -1) { string palName = lbxPalettes.SelectedItem.ToString(); BMD.Texture currentTexture = m_Model.ReadTexture(m_Model.m_TextureIDs[texName], m_Model.m_PaletteIDs[palName]); LoadBitmap(currentTexture); lblTexture.Text = "Texture: (ID " + m_Model.m_TextureIDs[texName] + ")"; } if (rbTexAsRefInBTP.Checked) { txtBTPTextureName.Text = texName; if (m_Model.m_TextureIDs.ContainsKey(texName)) { lblTexture.Text = "Texture: (ID " + m_Model.m_TextureIDs[texName] + ")"; } } }
private void lbxPalettes_SelectedIndexChanged(object sender, EventArgs e) { if (lbxPalettes.SelectedIndex < 0) { return; } string palName = lbxPalettes.Items[lbxPalettes.SelectedIndex].ToString(); if (rbTexAsRefInBTP.Checked) { txtBTPPaletteName.Text = palName; } if (lbxTextures.SelectedIndex != -1 && lbxPalettes.SelectedIndex != -1 && lbxPalettes.SelectedIndex < lbxPalettes.Items.Count) { string texName = lbxTextures.Items[lbxTextures.SelectedIndex].ToString(); if (m_Model.m_TextureIDs.ContainsKey(texName) && m_Model.m_PaletteIDs.ContainsKey(palName)) { BMD.Texture currentTexture = m_Model.ReadTexture(m_Model.m_TextureIDs[texName], m_Model.m_PaletteIDs[palName]); LoadBitmap(currentTexture); lblPalette.Text = "Palette: (ID " + m_Model.m_PaletteIDs[palName] + ")"; } } }
public Bitmap ConvertBMDTextureToBitmap(BMD.Texture texture) { Bitmap lol = new Bitmap((int)texture.m_Width, (int)texture.m_Height); for (int y = 0; y < (int)texture.m_Height; y++) { for (int x = 0; x < (int)texture.m_Width; x++) { lol.SetPixel(x, y, Color.FromArgb(texture.m_Data[((y * texture.m_Width) + x) * 4 + 3], texture.m_Data[((y * texture.m_Width) + x) * 4 + 2], texture.m_Data[((y * texture.m_Width) + x) * 4 + 1], texture.m_Data[((y * texture.m_Width) + x) * 4])); } } return(lol); }
private void btnExportAll_Click(object sender, EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); DialogResult result = fbd.ShowDialog(); String folderName = ""; if (result == DialogResult.OK) { folderName = fbd.SelectedPath; for (int i = 0; i < m_Model.m_Textures.Values.Count; i++) { BMD.Texture currentTexture = m_Model.m_Textures.Values.ElementAt(i); SaveTextureAsPNG(currentTexture, folderName + "/" + currentTexture.m_TexName + ".png"); } MessageBox.Show("Successfully exported " + m_Model.m_Textures.Values.Count + " texture(s) to:\n" + folderName); } }
private void LoadBitmap(BMD.Texture currentTexture) { Bitmap tex = new Bitmap((int)currentTexture.m_Width, (int)currentTexture.m_Height); for (int y = 0; y < (int)currentTexture.m_Height; y++) { for (int x = 0; x < (int)currentTexture.m_Width; x++) { tex.SetPixel(x, y, Color.FromArgb(currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 3], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 2], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 1], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4])); } } pbxTexture.Image = new Bitmap(tex); pbxTexture.Refresh(); }
private void btnExport_Click(object sender, EventArgs e) { if (lbxTextures.SelectedIndex != -1 && lbxPalettes.SelectedIndex != -1) { string texName = lbxTextures.Items[lbxTextures.SelectedIndex].ToString(); string palName = lbxPalettes.Items[lbxPalettes.SelectedIndex].ToString(); BMD.Texture currentTexture = m_Model.ReadTexture(m_Model.m_TextureIDs[texName], m_Model.m_PaletteIDs[palName]); SaveFileDialog export = new SaveFileDialog(); export.FileName = currentTexture.m_TexName; //Default name export.DefaultExt = ".png"; //Default file extension export.Filter = "PNG (.png)|*.png"; //Filter by .png if (export.ShowDialog() == DialogResult.Cancel) { return; } SaveTextureAsPNG(currentTexture, export.FileName); } else { MessageBox.Show("Please select a texture first."); } }