I have programmed for creating a animated GIF file from some jog files using NGif. The animated file (Just the automated slide show) is being created without any problem. The source images of the GIF (from which jpg files I created the animation) are in "Temp2" Folder. I wanted to delete that folder including files inside but the program is unable to handle that and giving the message: "...file is still being used by another process".
我已编程使用NGif从一些jog文件创建动画GIF文件。正在创建动画文件(只是自动幻灯片放映)没有任何问题。 GIF的源图像(我创建动画的jpg文件)位于“Temp2”文件夹中。我想删除包含文件的文件夹,但程序无法处理并给出消息:“...文件仍在被另一个进程使用”。
The function that I created is as below:
public void Create_Animated_GIF()
{
String Output_File_Path = Environment.CurrentDirectory + "\\Animation.gif";
AnimatedGifEncoder GEncoder = new AnimatedGifEncoder();
GEncoder.Start(Output_File_Path);
GEncoder.SetDelay(100);
GEncoder.SetRepeat(0);
for (int i = 0; i < 2; i++)
{
GEncoder.AddFrame(System.Drawing.Image.FromFile(Image_URLs[i]));
}
/*
try
{
System.IO.Directory.Delete(Environment.CurrentDirectory + "\\Temp2", true);
}
catch
{
}
*/
GEncoder.Finish();
System.IO.Directory.Delete(Environment.CurrentDirectory + "\\Temp2", true);
}
Here, I tried try-catch; it did not work!
在这里,我尝试了try-catch;它不起作用!
Another function wjere I used this Temp2 folder is as follows:
我使用这个Temp2文件夹的另一个功能如下:
public void Crop_Images()
{
if (!System.IO.Directory.Exists(Environment.CurrentDirectory + "\\Temp2\\"))
System.IO.Directory.CreateDirectory(Environment.CurrentDirectory + "\\Temp2\\");
for (int i = 0; i < 2; i++)
{
System.Drawing.Image Source_Image = System.Drawing.Image.FromFile(Environment.CurrentDirectory + "\\Temp\\" + i.ToString() + ".jpg");
System.Drawing.Bitmap Source_Image_Btmp = new System.Drawing.Bitmap(Source_Image);
System.Drawing.Rectangle Destin_Rect = new System.Drawing.Rectangle(1327, 1330, 632, 491);
System.Drawing.Image Destin_Image = Source_Image_Btmp.Clone(Destin_Rect, Source_Image_Btmp.PixelFormat);
Image_URLs[i] = Environment.CurrentDirectory + "\\Temp2\\" + i.ToString() + ".jpg";
Destin_Image.Save(Image_URLs[i]);
Source_Image.Dispose();
Source_Image_Btmp.Dispose();
Destin_Image.Dispose();
}
/*
try
{
System.IO.Directory.Delete(Environment.CurrentDirectory + "\\Temp", true);
}
catch
{
}
*/
System.IO.Directory.Delete(Environment.CurrentDirectory + "\\Temp", true);
}
Here, Temp folder is deleted successfully.
这里,Temp文件夹已成功删除。
I tried to call the delete command after calling the relevant function from main; but still it didn't work!
我从main调用相关函数后尝试调用delete命令;但它仍然无法正常工作!
Can anybody please help me how I can detach the folder from the process that I have created?
任何人都可以帮助我如何从我创建的进程中分离文件夹?
1 个解决方案
#1
1
Posting answer:
发布回答:
for (int i = 0; i < 2; i++)
{
using (var image = System.Drawing.Image.FromFile(Image_URLs[i]))
{
GEncoder.AddFrame(image);
}
}
#1
1
Posting answer:
发布回答:
for (int i = 0; i < 2; i++)
{
using (var image = System.Drawing.Image.FromFile(Image_URLs[i]))
{
GEncoder.AddFrame(image);
}
}