通过轨迹栏在图片框中加载图片(Windows) [英] Load a picture in picture box through track bar (Windows)

查看:88
本文介绍了通过轨迹栏在图片框中加载图片(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果跟踪栏位于1%上,则图像也将加载,例如从左到右的选取框仅占1%,并且跟踪栏将变为2,3,4,5,6 ..... 100%,因此图像也应根据轨迹栏加载.


If track bar is on 1% then the image will also load, like marquee from left to right only 1%, and track bar will go 2,3,4,5,6.....100%, so image should also load according to the trackbar.


using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
 
//Created by Raj Kumar Shukla @ 22*09*2012
namespace toolStripContainer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        double i;
        Image img = Image.FromFile("23.jpg");
        
        private void Form1_Load(object sender, EventArgs e)
        {            
            backgroundWorker1.RunWorkerAsync();
        }
 
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            for (i = 1; i <= 100;)
            {
                Thread.Sleep(100);
                backgroundWorker1.ReportProgress(Convert.ToInt32(i));
                i =i+0.2 ;
            }
        }
 
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            pictureBox1.Image = img;
            pictureBox1.Height = img.Height;
            pictureBox1.Width = img.Width;
            
           
            progressBar1.Value = e.ProgressPercentage;
           
            if (e.ProgressPercentage < 100)
            {
                this.Text ="Image loading Plz wait....";
                menuStrip1.Enabled = false;
            }
            else
            {
                this.Text = "Image Loading Completed";
                menuStrip1.Enabled = true;
            }
            
            trackBar1.Value = e.ProgressPercentage;
            
            pictureBox1.Width = e.ProgressPercentage * 10;
          
          
                    
        }
 
       public void openToolStripMenuItem_Click(object sender, EventArgs e)
        {           
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "Open Photo";
            dlg.Filter = "jpg files (*.jpg)|*.jpg";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
               img = new Bitmap(dlg.OpenFile());
            }
            dlg.Dispose();
            backgroundWorker1.RunWorkerAsync();
        }
 
       private void button1_Click(object sender, EventArgs e)
       {
          
       }
    }
}



[edit]添加了代码块,我将内容从问题的答案中移了出来-OriginalGriff [/edit]



[edit]Code block added, I moved the content from an Answer to the question - OriginalGriff[/edit]

推荐答案

您必须自己管理-图片可以不能以这种方式加载:发出load命令,然后加载整个图像,然后完整显示.可以通过使用Paint事件来伪造它,并且只显示已加载图像的一部分,但是我不知道为什么您会这样做.
You would have to manage that yourself - Images do not load in such a fashion: you issue the load command, and the whole image is loaded, and then displayed in it''s entirety. It is possible to fake it, by using the Paint event, and only displaying a portion of the loaded image, but why you would ant to do that, I do not know.


这篇关于通过轨迹栏在图片框中加载图片(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆