C# 有没有办法更快地更改图像大小?

C# 有没有办法更快地更改图像大小?,c#,winforms,C#,Winforms,也许是在记忆流中 private void satellitesToolStripMenuItem_Click(object sender, EventArgs e) { file_array_satellite = Directory.GetFiles(UrlsPath, "RainImage*.*"); for (int i = 0; i < file_array_satellite.Length; i++) { Image s = new Bi

也许是在记忆流中

private void satellitesToolStripMenuItem_Click(object sender, EventArgs e)
{
    file_array_satellite = Directory.GetFiles(UrlsPath, "RainImage*.*");
    for (int i = 0; i < file_array_satellite.Length; i++)
    {
        Image s = new Bitmap(file_array_satellite[i]);
        s = resizeImage(s, new Size(100, 100));
        s.Save(UrlsPath + "Changed" + i.ToString("D6") + ".jpg");
    }
    file_array_satellite = Directory.GetFiles(UrlsPath, "Changed*.*");
    if (file_array_satellite.Length > 0)
    {
        DateTime[] creationTimes8 = new DateTime[file_array_satellite.Length];
        for (int i = 0; i < file_array_satellite.Length; i++)
            creationTimes8[i] = new FileInfo(file_array_satellite[i]).CreationTime;
        Array.Sort(creationTimes8, file_array_satellite);
        file_indxs_satellite = 0;
        file_indxs_satellite = file_array_satellite.Length - 1;
        timer1.Enabled = true;
    }
}

public static Image resizeImage(Image imgToResize, Size size)
{
    return (Image)(new Bitmap(imgToResize, size));
}

private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
    file_array_satellite = Directory.GetFiles(UrlsPath, "RainImage*.*");
    for (int i = 0; i < file_array_satellite.Length; i++)
    {
        Image s = new Bitmap(file_array_satellite[i]);
        s = resizeImage(s, new Size(500, 500));
    }
    this.pictureBox1.Size = new Size(500, 500);
    pictureBox1.Location = new Point(this.Bounds.Width / 3,
                        this.Bounds.Height / 3);
    this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    pictureBox1.BringToFront();
}
private void-satellitesToolStripMenuItem\u单击(对象发送方,事件参数e)
{
file\u array\u satellite=Directory.GetFiles(UrlsPath,“RainImage**”);
对于(int i=0;i0)
{
DateTime[]creationTimes8=新的日期时间[文件\数组\卫星.Length];
对于(int i=0;i
在本例中,我在其中显示图像的pictureBox大小为100100 因此,我将图像大小更改为100100,并将其显示在pictureBox中。 然后,当我将鼠标移到pictureBox区域上时,pictureBox将移动到表单的中心,我将pictureBox的大小调整为500500,并将图像大小再次更改为500500,并在pictureBox中显示它们

private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {


                Image s = new Bitmap(file_array_satellite[file_indxs_satellite]);
                s = resizeImage(s, new Size(100, 100));
                pictureBox1.Load(file_array_satellite[file_indxs_satellite]);
                file_indxs_satellite = file_indxs_satellite - 1;
                if (file_indxs_satellite < 0)
                {
                    file_indxs_satellite = file_array_satellite.Length - 1;
                }
            }
            catch
            {
                timer1.Enabled = false;
            }
        }

        private void satellitesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            file_array_satellite = Directory.GetFiles(UrlsPath, "RainImage*.*");
            if (file_array_satellite.Length > 0)
            {
                DateTime[] creationTimes8 = new DateTime[file_array_satellite.Length];
                for (int i = 0; i < file_array_satellite.Length; i++)
                    creationTimes8[i] = new FileInfo(file_array_satellite[i]).CreationTime;
                Array.Sort(creationTimes8, file_array_satellite);
                file_indxs_satellite = 0;
                file_indxs_satellite = file_array_satellite.Length - 1;
                timer1.Enabled = true;
            }
        }

        public static Image resizeImage(Image imgToResize, Size size)
        {
            return (Image)(new Bitmap(imgToResize, size));
        }
问题是每次更改/转换硬盘上的图像大小几乎需要3-5秒

有没有更快的方法进行尺寸转换

编辑**

更改代码,尝试仅调整当前显示图像的大小,但pictureBox1中的图像现在大小不同,并且我在pictureBox中没有看到动画

private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {


                Image s = new Bitmap(file_array_satellite[file_indxs_satellite]);
                s = resizeImage(s, new Size(100, 100));
                pictureBox1.Load(file_array_satellite[file_indxs_satellite]);
                file_indxs_satellite = file_indxs_satellite - 1;
                if (file_indxs_satellite < 0)
                {
                    file_indxs_satellite = file_array_satellite.Length - 1;
                }
            }
            catch
            {
                timer1.Enabled = false;
            }
        }

        private void satellitesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            file_array_satellite = Directory.GetFiles(UrlsPath, "RainImage*.*");
            if (file_array_satellite.Length > 0)
            {
                DateTime[] creationTimes8 = new DateTime[file_array_satellite.Length];
                for (int i = 0; i < file_array_satellite.Length; i++)
                    creationTimes8[i] = new FileInfo(file_array_satellite[i]).CreationTime;
                Array.Sort(creationTimes8, file_array_satellite);
                file_indxs_satellite = 0;
                file_indxs_satellite = file_array_satellite.Length - 1;
                timer1.Enabled = true;
            }
        }

        public static Image resizeImage(Image imgToResize, Size size)
        {
            return (Image)(new Bitmap(imgToResize, size));
        }
private void timer1\u勾选(对象发送方,事件参数e)
{
尝试
{
图像s=新位图(文件数组卫星[文件索引卫星]);
s=调整图像大小(s,新大小(100100));
pictureBox1.Load(文件数组卫星[文件索引卫星]);
file_indxs_satellite=file_indxs_satellite-1;
if(文件索引卫星<0)
{
file_indxs_satellite=file_array_satellite.Length-1;
}
}
抓住
{
timer1.Enabled=false;
}
}
私有void卫星工具条带菜单项单击(对象发送方,事件参数e)
{
file\u array\u satellite=Directory.GetFiles(UrlsPath,“RainImage**”);
如果(文件\u数组\u satellite.Length>0)
{
DateTime[]creationTimes8=新的日期时间[文件\数组\卫星.Length];
对于(int i=0;i
要解决实施中的一些问题,请首先解决这些问题:

  • 您正在将大小从500x500调整到100x100,然后恢复到500x500>图像质量损失
  • 你没有处理你的图像
  • 如果只想显示一个图像,为什么要加载所有图像并调整其大小?只需调整您悬停在上面的图像的大小,然后您甚至不必将它们保存到磁盘
如果要显示大量图像,请提供一些常规提示:

  • 只加载那些您在GUI中实际查看的图像,一旦它们开始滚动,就再加载一次
  • 如果仍然很慢,请将它们加载到背景线程中,并在完成后逐个图像显示它们

要解决实施中的一些问题,请首先解决这些问题:

  • 您正在将大小从500x500调整到100x100,然后恢复到500x500>图像质量损失
  • 你没有处理你的图像
  • 如果只想显示一个图像,为什么要加载所有图像并调整其大小?只需调整您悬停在上面的图像的大小,然后您甚至不必将它们保存到磁盘
如果要显示大量图像,请提供一些常规提示:

  • 只加载那些您在GUI中实际查看的图像,一旦它们开始滚动,就再加载一次
  • 如果仍然很慢,请将它们加载到背景线程中,并在完成后逐个图像显示它们

要解决实施中的一些问题,请首先解决这些问题:

  • 您正在将大小从500x500调整到100x100,然后恢复到500x500>图像质量损失
  • 你没有处理你的图像
  • 如果只想显示一个图像,为什么要加载所有图像并调整其大小?只需调整您悬停在上面的图像的大小,然后您甚至不必将它们保存到磁盘
如果要显示大量图像,请提供一些常规提示:

  • 只加载那些您在GUI中实际查看的图像,一旦它们开始滚动,就再加载一次
  • 如果仍然很慢,请将其加载到背景中