コード例 #1
0
ファイル: Form1.cs プロジェクト: Crest10086/DeckBuilder2
        private void button4_Click(object sender, EventArgs e)
        {
            string ImageDir = null;

            mAppInterface.GetCardImgDirEx(ref ImageDir);

            if (!Directory.Exists(ImageDir))
            {
                ImageDir = DB2Config.GetInstance().GetSetting("ImagePath");
            }

            if (!Directory.Exists(ImageDir))
            {
                ImageDir = appPath + "\\Image\\";
            }

            FolderBrowserDialog openFolderDialog1 = new FolderBrowserDialog();

            openFolderDialog1.SelectedPath        = ImageDir;
            openFolderDialog1.Description         = "请选择卡图所在目录";
            openFolderDialog1.ShowNewFolderButton = false;

            if (openFolderDialog1.ShowDialog() == DialogResult.OK)
            {
                ImageDir = openFolderDialog1.SelectedPath;
            }
            else
            {
                return;
            }

            this.Text = "转换中,请稍候";
            DisableAllButton();

            //建立文件夹
            string outdirname = appPath + "\\LargeIco\\";

            if (!Directory.Exists(outdirname))
            {
                Directory.CreateDirectory(outdirname);
            }

            //转换大图标
            ImageList imagelist = new ImageList();

            imagelist.ImageSize        = new Size(47, 67);
            imagelist.ColorDepth       = ColorDepth.Depth32Bit;
            imagelist.TransparentColor = Color.White;

            //计算数量
            int total = 0;

            foreach (string sf in Directory.GetFiles(ImageDir))
            {
                FileInfo f = new FileInfo(sf);
                if (string.Equals(f.Extension, ".jpg", StringComparison.OrdinalIgnoreCase))
                {
                    total++;
                }
            }
            string stotal = total.ToString();

            progressBarX1.Maximum = total;
            int         i           = 0;
            CardLibrary cardLibrary = CardLibrary.GetInstance();

            foreach (string sf in Directory.GetFiles(ImageDir))
            {
                FileInfo f = new FileInfo(sf);
                if (string.Equals(f.Extension, ".jpg", StringComparison.OrdinalIgnoreCase))
                {
                    string id = f.Name.Substring(0, f.Name.LastIndexOf('.'));
                    try
                    {
                        int             id2  = int.Parse(id);
                        CardDescription card = cardLibrary.GetCardByID(id2);
                        if (card == null)
                        {
                            card = cardLibrary.GetCardByCheatCode(id);
                            if (card != null)
                            {
                                id = card.ID.ToString();
                            }
                            else
                            {
                                id = "0";
                            }
                        }
                    }
                    catch
                    {
                        CardDescription card = cardLibrary.GetCardByCheatCode(id);
                        if (card != null)
                        {
                            id = card.ID.ToString();
                        }
                        else
                        {
                            id = "0";
                        }
                    }
                    string filename = outdirname + "\\" + id + ".jpg";

                    if (!File.Exists(filename))
                    {
                        try
                        {
                            imagelist.Images.Add(Image.FromFile(f.FullName));
                            imagelist.Images[0].Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
                            imagelist.Images.RemoveAt(0);
                        }
                        catch
                        {
                        }
                    }

                    i++;
                    progressBarX1.Value = i;
                    progressBarX1.Text  = i.ToString() + "/" + stotal;
                    Application.DoEvents();
                }
            }

            this.Text = "辅助转换工具";
            EnableAllButton();
            MessageBox.Show("完成!");
        }