473,395 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

"Invalid parameter used" when calling Image.FromFile

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
4 3019
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
7
by: cnu | last post by:
Hi I have to write images(.gif/.bmp/.jpg/.ico), to db and read them. Uploading images to db works fine for me. Reading from db to byte is also ok. But, when I try to display them in my form...
4
by: sparks | last post by:
As you might know that "java.lang" package are automatically imported by the java compiler so that one don't need to write the import statement of that package in the source code. Are there any...
2
by: Tommy Vercetti | last post by:
I am working on a Managed C++ project and I get the following error: TestThread.cpp(3) : error C2859: c:\projects\ProjectName\debug\vc70.pdb is not the pdb file that was used when this...
6
by: Patrick Dugan | last post by:
Hello, I'm trying to load different images (icons) into a PictureBox1.Image. The first image loads just fine, but the second image always returns the error "Invalid property used." It doesn't...
3
by: Arnold | last post by:
I am having problem loading the image from the database. It gives this error: "Invalid parameter used." This is my source code: Private abyt() As Byte Private fo As New OpenFileDialog Private sf...
3
by: Paul | last post by:
Hi All, In my application, I wished to check certain things on each page load, so rather than paste the same code in each pages constructor, I thought it would be more logical to inherit from...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.