Exemple #1
0
        public MainWindow(string filename, Size s)
        {
            InitializeComponent();
            var backup = this.Size;

            try
            {
                if (s.Height <= 0 || s.Width <= 0)
                {
                    throw new Exception();
                }
                this.Size = s;
            }
            catch (Exception)
            {
                this.Size = backup;
            }
            this.MainPictureBox.AllowDrop = true;

            if (invoke_dll.read_profile())
            {
                has_icc = true;
            }

            this.Show();

            var box = new Processing();

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

                open(filename);

                box.Invoke(new Action(() =>
                {
                    box.Close();
                }));
                this.Focus();
            }
            catch (Exception)
            {
                box.Invoke(new Action(() =>
                {
                    box.Close();
                }));
                this.Focus();

                var errorbox = new Error();
                errorbox.maintext.Text  = "Unable to open this file.";
                errorbox.linklabel.Text = "Online Support";
                errorbox.link           = "https://liuziangexit.com/HEIF-Utility/Help/No1.html";
                errorbox.ShowDialog();

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

            try
            {
                var box = new SaveFileDialog();
                box.Title    = "Save";
                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  = "Can not save to " + box.FileName;
                    errorbox.linklabel.Text = "Online Support";
                    errorbox.link           = "https://liuziangexit.com/HEIF-Utility/Help/No2.html";
                    errorbox.ShowDialog();
                    return;
                }

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

                MessageBox.Show("Successfully saved to " + box.FileName);
                return;
            }
            catch (Exception)
            {
                box2.Invoke(new Action(() =>
                {
                    box2.Close();
                }));
                this.Focus();
                MessageBox.Show("An unknown error occurred.");
                return;
            }
        }