@Shayden

Как ускорить отрисовку изображения на picturebox.image и прочих элементов?

Имеется программа и ее форма, на которую из сети, загружаются изображения. Чтоб изображение сменить, нажимаю button.click. Однако, есть один момент, а именно: после нажатия на button по идее должно появится моментально следующее изображение(по скорости аналогично с перелистыванием фотографий в "средстве просмотра фотографии Windows" :))) только лишь с очень крайне редкими задержками). И оно появляется, но с задержкой в одну или около одной секунды, а так по идее быть не должно и есть подобные программы моей, на которых как раз так и происходит как мне и необходимо, без задержек! Как и можно ли в данном коде ускорить отрисовку/появление изображений на picturebox.image и прочих элементов что появляются вместе с ним? Возможно даже в коде имеются элементы, которых вообще и быть не должно и их выкинуть из кода можно:

private void ricVision()
        {
            try
            {
                if (!this.locker && (this.waitVision.Count > 0))
                {
                    this.textBox2.Focus();                   
                    this.locker = true;
                    string[] strArray = this.waitVision[0];
                    if (strArray[9].ToString() != "-")
                    {
                        this.textBox2.Text = strArray[9].ToString();
                    }
                    int num = Convert.ToInt32(strArray[0].ToString());
                    int num2 = Convert.ToInt32(strArray[1].ToString());
                    int index = Convert.ToInt32(strArray[6].ToString());
                    this.visionType = strArray[2].ToString();
                    this.Registor = strArray[3].ToString();
                    this.WordsTwo = strArray[4].ToString();
                    this.label7.Text = this.Registor;
                    this.label8.Text = strArray[4].ToString();
                    this.label16.Text = strArray[10].ToString();
                    {
                        if (label16.Text.Length > 5)
                            label16.Text = label16.Text.Substring(0, 5);
                    };
                    this.label19.Text = strArray[12].ToString();
                    this.label21.Text = this.BASE64;
                    this.label23.Text = strArray[13].ToString();
                    this.BASE64 = strArray[14].ToString();
                    DoubleBuffered = true;
                    if (label7.Text == "False")
                    {
                        dataGridView1.Rows[index].Cells[1].Style.BackColor = Color.Empty;
                        DoubleBuffered = true;
                    }
                    else if (label7.Text == "True")
                    {
                        dataGridView1.Rows[index].Cells[1].Style.BackColor = Color.Tomato;
                        DoubleBuffered = true;
                    }
                    if (label8.Text == "False")
                    {
                        dataGridView1.Rows[index].Cells[3].Style.BackColor = Color.Empty;
                        DoubleBuffered = true;
                    }
                    else if (label8.Text == "True")
                    {
                        dataGridView1.Rows[index].Cells[3].Style.BackColor = Color.Tomato;
                        DoubleBuffered = true;
                    }
                    this.label10.Text = this.visionType;
                    this.pictureBox1.Width = num;
                    this.pictureBox1.Height = num2;
                    this.panel2.Visible = true;
                    {
                        this.label13.Text = this.dataGridView1.Rows[index].Cells[3].Value.ToString();
                        if (double.Parse(label13.Text) < 0)
                        {
                            panel2.BackColor = Color.GreenYellow;
                            this.dataGridView1.Rows[index].DefaultCellStyle.BackColor = Color.GreenYellow;
                            if (label8.Text == "True")
                            {
                                panel2.BackColor = Color.RoyalBlue;
                                dataGridView1.Rows[index].DefaultCellStyle.BackColor = Color.RoyalBlue;
                                label13.ForeColor = Color.RoyalBlue;
                                DoubleBuffered = true;
                            }
                        }
                        else
                        {
                            panel2.BackColor = Color.Gainsboro;
                            if (label8.Text == "False")
                            {
                                panel2.BackColor = Color.Gainsboro;
                                dataGridView1.Rows[index].DefaultCellStyle.BackColor = Color.Gold;
                                label13.ForeColor = Color.Green;
                                DoubleBuffered = true;
                            }
                        }
                    };
                    string s = strArray[5].ToString().Substring(0, strArray[5].ToString().Length - 9).Replace(@"\/", "/");
                    this.visionId = strArray[5].ToString().Substring(strArray[5].ToString().Length - 9);
                    this.visionThread = Convert.ToInt32(strArray[6]);      
                    this.label12.Text = strArray[7].ToString();                  
                    Bitmap bitmap = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
                    string path = "";
                    this.pictureBox1.DrawToBitmap(bitmap, this.pictureBox1.ClientRectangle);
                    this.pictureBox1.Refresh();
                    DoubleBuffered = true;
                    this.ResumeLayout(false);
                    Form1 form = (Form1)Application.OpenForms[0];
                    this.ActiveControl = textBox2;
                    TopMost = true;
                    TopLevel = true;
                    textBox2.Select();
                    form.Activate();
                    form.Focus();
                    this.showCaptcha();
                    this.timer1.Enabled = true;
                    ImageFormat bmp = null;
                    Graphics gdi = Graphics.FromImage(bitmap);
                    switch (Path.GetExtension(path))
                    {
                        case ".bmp":
                            bmp = ImageFormat.Bmp;
                            break;

                        case ".png":
                            bmp = ImageFormat.Png;
                            break;

                        case ".jpeg":
                        case ".jpg":
                            bmp = ImageFormat.Jpeg;
                            break;

                        case ".gif":
                            bmp = ImageFormat.Gif;
                            break;
                    }
                        using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(s)))
                        {
                            this.pictureBox1.Image = Image.FromStream(stream);                          
                            int clickeditem = 0;
                            clickeditem++;
                            switch (clickeditem)
                            {
                                case 1:
                                    this.pictureBox1.Image = Image.FromStream(stream);
                                    break;
                                case 2:
                                    this.pictureBox1.Image = Image.FromStream(stream);
                                    break;
                                case 3:
                                    this.pictureBox1.Image = Image.FromStream(stream);
                                    break;
                            }              
                        }
                    }
                }            
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());                
            }
        }
  • Вопрос задан
  • 85 просмотров
Пригласить эксперта
Ответы на вопрос 1
А вы, показывая одно изображение, сразу грузите следующее (может даже парочку). Не важно - из сети, или с диска, идея одна и та же.

Попробуйте полистать в виндовом средстве просмотра БЫСТРО - возможно заметите задержку.
А вообще, раз речь идёт о сети, то у вас отличная возможность ознакомиться с кэшированием.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы