By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

"Invalid parameter used" when calling Image.FromFile

P: n/a
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.

Jul 19 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
es********@hotmail.com wrote:
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.

--
Hope this helps,
Tom Spink

Google first, ask later.
Jul 19 '06 #2

P: n/a
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.
Tom Spink wrote:
es********@hotmail.com wrote:
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.

--
Hope this helps,
Tom Spink

Google first, ask later.
Jul 20 '06 #3

P: n/a
es********@hotmail.com wrote:
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.
Tom Spink wrote:
>es********@hotmail.com wrote:
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.

--
Hope this helps,
Tom Spink

Google first, ask later.
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?

--
Hope this helps,
Tom Spink

Google first, ask later.
Jul 20 '06 #4

P: n/a
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.

Tom Spink wrote:
es********@hotmail.com wrote:
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.
Tom Spink wrote:
es********@hotmail.com wrote:

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.

--
Hope this helps,
Tom Spink

Google first, ask later.

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?

--
Hope this helps,
Tom Spink

Google first, ask later.
Jul 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.