Wednesday, 7 August 2013

Why does DotNetZip cause OutOfMemory Exception in Images?

Why does DotNetZip cause OutOfMemory Exception in Images?

I have tried zipping an .PNG image file to a zip file using DotNetZip but
after I extract it later on and use the Image.FromFile method it gives me
an OutOfMemory Exception. I have tried other images but it gives me the
same result. If I override the image with the file that wasn't zipped I
don't get that error.
Compression Code
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = system.Abriviation + " Game|*" + system.Extention;
sfd.AddExtension = true;
sfd.ShowDialog();
if (sfd.FileName != "")
{
StreamWriter write = new StreamWriter(Application.StartupPath +
"\\meta");
write.WriteLine(txtName.Text);
write.WriteLine(new FileInfo(txtGame.Text).Extension);
write.WriteLine(txtCompany.Text);
write.Close();
File.Copy(txtGame.Text, Application.StartupPath + "\\game" + new
FileInfo(txtGame.Text).Extension);
File.Copy(txtGame.Text, Application.StartupPath + "\\icon.png");
ZipFile zip = new ZipFile();
zip.AddFile(Application.StartupPath + "\\meta", "");
zip.AddFile(Application.StartupPath + "\\game" + new
FileInfo(txtGame.Text).Extension, "");
zip.AddFile(Application.StartupPath + "\\icon.png", "");
zip.Save(sfd.FileName);
zip.Dispose();
File.Delete(Application.StartupPath + "\\game" + new
FileInfo(txtGame.Text).Extension);
File.Delete(Application.StartupPath + "\\icon.png");
File.Delete(Application.StartupPath + "\\meta");
Close();
}
Extraction Code
String name = "", company = "", ext = "";
FileInfo info = new FileInfo(file);
StreamReader read = new StreamReader(file);
name = read.ReadLine();
ext = read.ReadLine();
company = read.ReadLine();
read.Close();
Image icon = null;
if (File.Exists(system.GameMetaPath + "\\" + info.Name + ".png"))
{
icon = Image.FromFile(system.GameMetaPath + "\\" + info.Name + ".png");
}
return new Game(system, name, company, system.GamePath + "\\" + info.Name
+ ext, file, icon);
Is there a way to get around or fix this problem?

No comments:

Post a Comment