我正在执行一个文件并执行2个操作。调整大小并将其放置在图片框中,然后重新调整大小并保存。进程无法访问文件...因为它正在被另一个进程使用
第一个调整大小操作在将其作为缩略图放入窗口后很顺利,但是在调整大小之后,第二个调整大小操作失败,说它正在使用中。
从我的理解我没有关闭文件或流。对此的解决方案是“使用”命令,但不管我放在哪里,我都会遇到错误。
第一缩放代码:
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string[] droppedfiles = (string[])e.Data.GetData(DataFormats.FileDrop);
PB_Picture.Image = ScaleImage(Image.FromFile(droppedfiles[0]), 180, 140);
}
我想:
private void Form1_DragDrop(object sender, DragEventArgs e)
{
using (string[] droppedfiles = (string[])e.Data.GetData(DataFormats.FileDrop));
PB_Picture.Image = ScaleImage(Image.FromFile(droppedfiles[0]), 180, 140);
}
,但得到的一些误区。
好吧,你不能在'using'语句中使用数组,因为它没有实现IDisposable。尝试删除使用语句。 – Ingenioushax
第二次调整大小操作在哪里? –
您必须处理从Image.FromFile返回的图像,而不是您的字符串数组。 –