也许以某种方式在内存流中?
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();
}
在这种情况下,我显示图像的图片框大小为 100,100,因此我将图像大小更改为 100,100 并将其显示在图片框中。然后,当我将鼠标移到图片框区域上时,图片框正在移动到窗体的中心,我将图片框的大小调整为 500,500,并将图像大小再次更改为 500,500 并将它们显示在图片框中。
问题是每次更改/转换硬盘上的图像大小几乎需要 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));
}