private void button3_Click(object sender, EventArgs e) { if (selectedImage == null || selectedImage.replacementLen <= 0) { return; } DialogResult res = saveFileDialog3.ShowDialog(); if (res != DialogResult.OK) { return; } Bitmap bm = new Bitmap(selectedImage.width, selectedImage.height); CBitReader cr = new CBitReader(selectedImage.replacement); switch (selectedImage.flags & 0xFF) { case 2: CR6Ti.DecodeOpaque1(cr, bm, selectedImage.width, selectedImage.height, selectedImage.depth); break; case 3: CR6Ti.DecodeTransparent(cr, bm, selectedImage.width, selectedImage.height, selectedImage.depth); break; } bm.Save(saveFileDialog3.FileName); bm.Dispose(); }
private void button1_Click(object sender, EventArgs e) { if (selectedImage == null) { return; } DialogResult res = openFileDialog3.ShowDialog(); if (res == DialogResult.OK) { Bitmap bitmap = new Bitmap(selectedImage.width, selectedImage.height); statusLabel.Text = "Resizing image and creating bitmap ..."; using (Graphics g = Graphics.FromImage((Image)bitmap)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(Image.FromFile(openFileDialog3.FileName), 0, 0, selectedImage.width, selectedImage.height); } MemoryStream stream = new MemoryStream(); CBitWriter bw = new CBitWriter(); switch (selectedImage.flags & 0xFF) { case 2: if ((selectedImage.depth & 0x4) != 0) { statusLabel.Text = "Encoding opaque image (might take a while) ..."; CR6Ti.WriteOpaque1(bitmap, bw, selectedImage.width, selectedImage.height); } else { throw new NotSupportedException("Writing Opaque2 images is not supported"); } break; case 3: statusLabel.Text = "Encoding transparent image (might take a while) ..."; CR6Ti.WriteTransparent(bitmap, bw, selectedImage.width, selectedImage.height); break; default: throw new NotSupportedException("Unknown image type"); } statusLabel.Text = "Saving in byte format ..."; bw.CopyToStream(stream); stream.Flush(); selectedImage.replacement = stream.ToArray(); selectedImage.replacementLen = (UInt32)stream.Length; checkBoxReplaced.Checked = true; button2.Enabled = true; stream.Dispose(); stream.Close(); bitmap.Dispose(); if ((selectedImage.flags & 0xFF) == 2 || (selectedImage.flags & 0xFF) == 3) { Bitmap bm = new Bitmap(selectedImage.width, selectedImage.height); CBitReader cr = new CBitReader(selectedImage.replacement); switch (selectedImage.flags & 0xFF) { case 2: CR6Ti.DecodeOpaque1(cr, bm, selectedImage.width, selectedImage.height, selectedImage.depth); break; case 3: CR6Ti.DecodeTransparent(cr, bm, selectedImage.width, selectedImage.height, selectedImage.depth); break; } pictureBox2.Image = bm; } else { if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); } pictureBox2.Image = null; } statusLabel.Text = "Ready"; } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex == -1) { textBoxTitle.Clear(); textBoxTitle.ReadOnly = true; comboBox1.Enabled = false; button1.Enabled = false; button2.Enabled = false; checkBoxReplaced.Checked = false; selectedImage = null; return; } selectedImage = (PackageImage)comboBox1.SelectedItem; button1.Enabled = true; textBoxTitle.Text = selectedImage.title; textBoxTitle.ReadOnly = false; labelHash.Text = selectedImage.hash; labelSize.Text = selectedImage.width + " x " + selectedImage.height; if (File.Exists(Path.Combine(pkgLocation, Path.Combine("Dump", selectedImage.hash + ".png")))) { pictureBox1.Image = Image.FromFile(Path.Combine(pkgLocation, Path.Combine("Dump", selectedImage.hash + ".png"))); } else { if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = null; } if (selectedImage.replacementLen > 0) { checkBoxReplaced.Checked = true; button2.Enabled = true; if ((selectedImage.flags & 0xFF) == 2 || (selectedImage.flags & 0xFF) == 3) { Bitmap bm = new Bitmap(selectedImage.width, selectedImage.height); CBitReader cr = new CBitReader(selectedImage.replacement); switch (selectedImage.flags & 0xFF) { case 2: CR6Ti.DecodeOpaque1(cr, bm, selectedImage.width, selectedImage.height, selectedImage.depth); break; case 3: CR6Ti.DecodeTransparent(cr, bm, selectedImage.width, selectedImage.height, selectedImage.depth); break; } pictureBox2.Image = bm; } else { if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); } pictureBox2.Image = null; } } else { checkBoxReplaced.Checked = false; if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); } pictureBox2.Image = null; } switch (selectedImage.flags & 0xFF) { case 2: if ((selectedImage.depth & 0x4) != 0) { labelType.Text = "Opaque1"; } else { labelType.Text = "Opaque2"; } break; case 3: labelType.Text = "Transparent"; break; default: labelType.Text = "Unknown"; break; } }