"Invalid parameter used" when calling Image.FromFile

E

escristian

Hello.

I'm trying to create an Image so I use something like this:
Image newImage = Image.FromFile(filename);

Now when it's a bmp file and certain .gif files it gives me an
exception that says: "Invalid parameter used". The gif an bmp files are
valid image files, I can open them in any graphics software and windows
can do the preview.

Can anyone tell me why this is hapenning and what I can do about this.
The problem is that when I get the exception my forms hangs and I can't
give back control to the user. Also just as a test I used the overload
for .FromFile method and it gives me the same result

Thank you.
 
T

Tom Spink

Hello.

I'm trying to create an Image so I use something like this:
Image newImage = Image.FromFile(filename);

Now when it's a bmp file and certain .gif files it gives me an
exception that says: "Invalid parameter used". The gif an bmp files are
valid image files, I can open them in any graphics software and windows
can do the preview.

Can anyone tell me why this is hapenning and what I can do about this.
The problem is that when I get the exception my forms hangs and I can't
give back control to the user. Also just as a test I used the overload
for .FromFile method and it gives me the same result

Thank you.

Hi,

Can you provide a code sample, please?

And, just for a note, you can catch the exception thrown by using a
try...catch block, if you want to handle the exception in a friendly way.
 
E

escristian

Basically I have a MainForm which displays a dialog form to set an
Icon.

The problem I have occurs when the user clicks on the set icon button
and I call an OpenFileDialog object ShowDialog method.

try
{
if (m_oOpenFileDialog.ShowDialog() == true)
{
Image newImage = Image.FromFile(m_oOpenFileDialog.FileName, true);
//logic to set icon in app
}
}
catch
{
MessageBox.Show(m_oResManager.GetString("Invalid size for image."),

m_oResManager.GetString("Error"), MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

The exception is thrown when I call FromFile. The funny thing is i was
trying this out in my dev computer and the application would hang. I
gave a copy to QA so they can do some preliminary tests on it and the
application doesn't hang but it does always end up in an exception.
Even with the icons that would work on my dev computer

This one is a weird one.
 
T

Tom Spink

Basically I have a MainForm which displays a dialog form to set an
Icon.

The problem I have occurs when the user clicks on the set icon button
and I call an OpenFileDialog object ShowDialog method.

try
{
if (m_oOpenFileDialog.ShowDialog() == true)
{
Image newImage = Image.FromFile(m_oOpenFileDialog.FileName, true);
//logic to set icon in app
}
}
catch
{
MessageBox.Show(m_oResManager.GetString("Invalid size for image."),

m_oResManager.GetString("Error"), MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

The exception is thrown when I call FromFile. The funny thing is i was
trying this out in my dev computer and the application would hang. I
gave a copy to QA so they can do some preliminary tests on it and the
application doesn't hang but it does always end up in an exception.
Even with the icons that would work on my dev computer

This one is a weird one.

Hi,

You have a slight error in your code on the ShowDialog conditional.
ShowDialog does not return a boolean, it returns an enumeration value of
type DialogResult. You need to check if ShowDialog returns a
DialogResult.OK.

What's the type of exception thrown? Is it an InvalidArgumentException?
 
E

escristian

Ye sorry about that.

I didnt copy the exact code from my app because there was so much other
stuff that I thought writing it again would be faster then cleaning it
up. but don't worry I Use DialogResult.

As for the exception type it is a ArgumentException. Message is
"Invalid parameter used".

I thought maybe it had something to do with getting the image files
from the network (network at work can be tricky sometimes), so i tried
getting the same image files but from my local disk. Still the same
problem. It's the BMP files and certain gifs, that cause this problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top