Beispiel #1
0
        private void 批量转换ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var box = new Batch_Conversion();

            box.ShowDialog();
        }
Beispiel #2
0
        private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var box2 = new Processing();

            try
            {
                var box = new SaveFileDialog();
                box.Title    = "保存";
                box.Filter   = "JPEG(.jpg)|*.jpg";
                box.FileName = Batch_Conversion.make_output_filename(filename);
                if (box.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                if (box.FileName == "")
                {
                    return;
                }

                var sq = new setjpgquality();
                sq.ShowDialog();

                Thread T;
                T = new Thread(new ThreadStart(new Action(() =>
                {
                    box2.ShowDialog();
                })));
                T.IsBackground = true;
                T.Start();

                while (!box2.IsHandleCreated)
                {
                    Thread.Sleep(100);
                }

                try
                {
                    int    copysize = 0;
                    byte[] write_this;
                    write_this = invoke_dll.invoke_heif2jpg(heicfile, sq.value, "tmp/temp_bitstream.hevc", ref copysize, sq.includes_exif, sq.color_profile);

                    FileStream   fs     = new FileStream(box.FileName, FileMode.Create);
                    BinaryWriter writer = new BinaryWriter(fs);
                    try
                    {
                        writer.Write(write_this, 0, copysize);
                        writer.Close();
                        fs.Close();
                    }
                    catch (Exception ex) {
                        try
                        {
                            writer.Close();
                            fs.Close();
                        }
                        catch (Exception) { }
                        throw ex;
                    }
                }
                catch (Exception)
                {
                    box2.Invoke(new Action(() =>
                    {
                        box2.Close();
                    }));
                    this.Focus();

                    var errorbox = new Error();
                    errorbox.maintext.Text  = "无法保存到 " + box.FileName;
                    errorbox.linklabel.Text = "转到在线帮助";
                    errorbox.link           = "https://liuziangexit.com/HEIF-Utility/Help/No2.html";
                    errorbox.ShowDialog();
                    return;
                }

                box2.Invoke(new Action(() =>
                {
                    box2.Close();
                }));
                this.Focus();

                MessageBox.Show("成功保存到 " + box.FileName);
                return;
            }
            catch (Exception)
            {
                box2.Invoke(new Action(() =>
                {
                    box2.Close();
                }));
                this.Focus();
                MessageBox.Show("发生未知错误。");
                return;
            }
        }