C# Programming
03-06-2010, 02:12 AM
Hi,
i am trying to write a title to an image and save it back to its current ******** but i am having a problem as the following message is being thrown:
A generic error occured in GDI+
A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
System.Drawing
A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
System.Drawing
Error code: -2147467259
" at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)\r\n
at System.Drawing.Image.Save(String filename, ImageFormat format)\r\n at ZooSystem.ImageViewer.ApplyChanges()
in E:\\ZooSystem\\\ImageViewer.cs:line 520"
I have checked the permissions for each of the images in the folder and they all have FullControl/Read/Write/Modify permissions but the folder has "Read-Only" enabled.
The folder was created on the Internal Hard drive of the computer and I am using Windows Vista Home Premium 32-bit. I am using MS VS 2008 Pro edition which i run in Admin mode.
If i save the images to another folder say one of the Public folders then the above exception is not thrown.
But I would like to save my images to the same folder if possible?
How could i go about doing this? I would appreciate if somebody could help me with the above. I have been trying to fix it for past 2 hours.
Thanks,
Here is the code i am using:
private void ApplyChanges()
{
//check if the destination folder in the textbox is blank in order to save a single image
//using the Save-file dialog feature.
if(txtBoxOut.Text.Equals("")
{
//write the title to the image by calling a write method
//show the save file dialog and check if result is OK.
//call the custom save method
if(sfd.ShowDialog()==DialogResult.OK)
{
this.SaveTheImage(sfd.FileName,this.bmp);
}
}
else if(txtBoxOut.Text != "")
{
string destFolder = txtBoxOut.text
foreach(string filePath in filePaths)
{
this.bmp = Image.FromFile(filePath);
string fileName = Path.GetFileName(filePath);
try
{
//write the title to the global image
//check folder
if(destFolder.EndsWith("\\")
{
//use the inbuilt save method
this.bmp.Save(destFolder+fileName+ImageFormat.Jpeg);
}
else
{
this.bmp.Save(destFolder+"\\"+fileName+ImageFormat.Jpeg);
}
}
catch(Exception e)
{
Console.WriteLine(e.message.ToString());
}
}
}
}
i am trying to write a title to an image and save it back to its current ******** but i am having a problem as the following message is being thrown:
A generic error occured in GDI+
A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
System.Drawing
A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
System.Drawing
Error code: -2147467259
" at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)\r\n
at System.Drawing.Image.Save(String filename, ImageFormat format)\r\n at ZooSystem.ImageViewer.ApplyChanges()
in E:\\ZooSystem\\\ImageViewer.cs:line 520"
I have checked the permissions for each of the images in the folder and they all have FullControl/Read/Write/Modify permissions but the folder has "Read-Only" enabled.
The folder was created on the Internal Hard drive of the computer and I am using Windows Vista Home Premium 32-bit. I am using MS VS 2008 Pro edition which i run in Admin mode.
If i save the images to another folder say one of the Public folders then the above exception is not thrown.
But I would like to save my images to the same folder if possible?
How could i go about doing this? I would appreciate if somebody could help me with the above. I have been trying to fix it for past 2 hours.
Thanks,
Here is the code i am using:
private void ApplyChanges()
{
//check if the destination folder in the textbox is blank in order to save a single image
//using the Save-file dialog feature.
if(txtBoxOut.Text.Equals("")
{
//write the title to the image by calling a write method
//show the save file dialog and check if result is OK.
//call the custom save method
if(sfd.ShowDialog()==DialogResult.OK)
{
this.SaveTheImage(sfd.FileName,this.bmp);
}
}
else if(txtBoxOut.Text != "")
{
string destFolder = txtBoxOut.text
foreach(string filePath in filePaths)
{
this.bmp = Image.FromFile(filePath);
string fileName = Path.GetFileName(filePath);
try
{
//write the title to the global image
//check folder
if(destFolder.EndsWith("\\")
{
//use the inbuilt save method
this.bmp.Save(destFolder+fileName+ImageFormat.Jpeg);
}
else
{
this.bmp.Save(destFolder+"\\"+fileName+ImageFormat.Jpeg);
}
}
catch(Exception e)
{
Console.WriteLine(e.message.ToString());
}
}
}
}