private void previewToolStripMenuItem_Click(object sender, EventArgs e) { ImageSize imgSize; //string imgName = (tex2D.getFileFormat() == ".tga") ? "exec\\" + "preview00" : "exec\\" + "preview"; string imgName = "exec\\preview" + tex2D.getFileFormat(); if (File.Exists("exec\\preview.tga")) File.Delete("exec\\preview.tga"); if (File.Exists("exec\\preview.dds")) File.Delete("exec\\preview.dds"); if (tex2D.imgList.Count != 1) imgSize = tex2D.imgList.Where(img => (img.imgSize.width <= 512 || img.imgSize.height <= 512) && img.offset != -1).Max(image => image.imgSize); else imgSize = tex2D.imgList.First().imgSize; tex2D.extractImage(imgSize.ToString(), ME3Directory.cookedPath, imgName); if (File.Exists(Path.GetFullPath(imgName))) { if (pictureBox.Image != null) pictureBox.Image.Dispose(); pictureBox.SizeMode = PictureBoxSizeMode.AutoSize; if (tex2D.getFileFormat() == ".dds") { DDSImage ddsImage = new DDSImage(imgName); pictureBox.Image = ddsImage.ToPictureBox(pictureBox.Width, pictureBox.Height); } else // .tga { TargaImage ti = new TargaImage(imgName); pictureBox.Image = ti.Image; } pictureBox.Refresh(); listView1.Visible = false; panelImage.Visible = true; if (File.Exists(imgName)) File.Delete(imgName); } }
/// <summary> /// Loads a Targa image file into a Bitmap object. /// </summary> /// <param name="sFileName">The Targa image filename</param> /// <returns>A Bitmap object with the Targa image loaded into it.</returns> public static Bitmap LoadTargaImage(string sFileName) { Bitmap b = null; using (TargaImage ti = new TargaImage(sFileName)) { b = new Bitmap(ti.Image); } return b; }