AmaroK86.ImageFormat.DDSImage.ToPictureBox C# (CSharp) Method

ToPictureBox() public method

public ToPictureBox ( int picBoxWidth, int picBoxHeight ) : Bitmap
picBoxWidth int
picBoxHeight int
return System.Drawing.Bitmap
        public Bitmap ToPictureBox(int picBoxWidth, int picBoxHeight)
        {
            try
            {
                return mipMaps.Last(image => image.width >= picBoxWidth && image.height >= picBoxHeight).bitmap;
            }
            catch (InvalidOperationException)
            {
                return mipMaps.First().bitmap;
            }
        }

Usage Example

示例#1
0
        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);
            }
        }