473,757 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Image error "Invalid Paramter used"

Hello,
I'm trying to load different images (icons) into a PictureBox1.Ima ge.

The first image loads just fine, but the second image always returns the
error "Invalid property used."
It doesn't matter what icons are loaded. The first always shows up and any
icons after that give me the error.

Here is the offending code:
The "DestinationPat h" variable is the full path and filename of the icon
Private Sub LoadIcon()
Dim FStream As New FileStream(Dest inationPath, FileMode.Open)
Try
PictureBox1.Ima ge = System.Drawing. Image.FromStrea m(FStream)
Catch Err As Exception
MsgBox(Err.Mess age)
End Try
FStream.Close()
End Sub
Is there something I am forgetting to close or clear?


Nov 21 '05 #1
6 2145
Welcome to MS graphics!!!! (I am not a big fan of .NET graphics).

You are closing your file stream in the subroutine. Once you do that,
the picturebox cannot manipulate the image or even re-draw it.

Since the file must stay open so the picturebox can use it, try
this....

Private Sub LoadIcon()
'set up an image
Dim newimage As System.Drawing. Image
'fill from file
'but the file will stay open !!!!!
newimage = System.Drawing. Image.FromFile( lcl_filename)
'this will close the last file opened
If Not PictureBox1.Ima ge Is Nothing Then
PictureBox1.Ima ge.Dispose()
End If

Try
PictureBox1.Ima ge = newimage
Catch Err As Exception
MsgBox(Err.Mess age)
End Try

End Sub

Now the file will be opened and locked by the picturebox, but you will
be able to do what you are trying.

HTH
Barry
On Sat, 2 Oct 2004 20:11:08 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:
Hello,
I'm trying to load different images (icons) into a PictureBox1.Ima ge.

The first image loads just fine, but the second image always returns the
error "Invalid property used."
It doesn't matter what icons are loaded. The first always shows up and any
icons after that give me the error.

Here is the offending code:
The "DestinationPat h" variable is the full path and filename of the icon
Private Sub LoadIcon()
Dim FStream As New FileStream(Dest inationPath, FileMode.Open)
Try
PictureBox1.Ima ge = System.Drawing. Image.FromStrea m(FStream)
Catch Err As Exception
MsgBox(Err.Mess age)
End Try
FStream.Close()
End Sub
Is there something I am forgetting to close or clear?


bceggersATcomca stDOTnet
Nov 21 '05 #2
I tried the code but after it loads a few icons it gives me an out-of-memory
error.

I'm really beginning to "love" vb.net right now. Some things that were
simple are now ridiculously hard
and other things are easier.

Do I need to dispose of the newimage after it gets placed into the
Picturebox?
"Barry" <bc******@castc om.com> wrote in message
news:f7******** *************** *********@4ax.c om...
Welcome to MS graphics!!!! (I am not a big fan of .NET graphics).

You are closing your file stream in the subroutine. Once you do that,
the picturebox cannot manipulate the image or even re-draw it.

Since the file must stay open so the picturebox can use it, try
this....

Private Sub LoadIcon()
'set up an image
Dim newimage As System.Drawing. Image
'fill from file
'but the file will stay open !!!!!
newimage = System.Drawing. Image.FromFile( lcl_filename)
'this will close the last file opened
If Not PictureBox1.Ima ge Is Nothing Then
PictureBox1.Ima ge.Dispose()
End If

Try
PictureBox1.Ima ge = newimage
Catch Err As Exception
MsgBox(Err.Mess age)
End Try

End Sub

Now the file will be opened and locked by the picturebox, but you will
be able to do what you are trying.

HTH
Barry
On Sat, 2 Oct 2004 20:11:08 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:
Hello,
I'm trying to load different images (icons) into a PictureBox1.Ima ge.

The first image loads just fine, but the second image always returns the
error "Invalid property used."
It doesn't matter what icons are loaded. The first always shows up and
any
icons after that give me the error.

Here is the offending code:
The "DestinationPat h" variable is the full path and filename of the icon
Private Sub LoadIcon()
Dim FStream As New FileStream(Dest inationPath, FileMode.Open)
Try
PictureBox1.Ima ge = System.Drawing. Image.FromStrea m(FStream)
Catch Err As Exception
MsgBox(Err.Mess age)
End Try
FStream.Close()
End Sub
Is there something I am forgetting to close or clear?


bceggersATcomca stDOTnet

Nov 21 '05 #3
No, don't dispose of newimage. If you try that you will find that the
picturebox can't handle the image.

Is your out of memory error a "GDI+" error or a system error?

How many icons can you load before you get this error? I don't have
any problems with 30+ times into the subroutine.

Barry
On Sun, 3 Oct 2004 10:48:56 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:
I tried the code but after it loads a few icons it gives me an out-of-memory
error.

I'm really beginning to "love" v b.netrightnow.S omethingsthatwe re
simple are now ridiculously hard
and other things are easier.

Do I need to dispose of the newimage after it gets placed into the
Picturebox?
"Barry" <bc******@castc om.com> wrote in message
news:f7******* *************** **********@4ax. com...
Welcome to MS graphics!!!! (I am not a big fan of .NET graphics).

You are closing your file stream in the subroutine. Once you do that,
the picturebox cannot manipulate the image or even re-draw it.

Since the file must stay open so the picturebox can use it, try
this....

Private Sub LoadIcon()
'set up an image
Dim newimage As System.Drawing. Image
'fill from file
'but the file will stay open !!!!!
newimage = System.Drawing. Image.FromFile( lcl_filename)
'this will close the last file opened
If Not PictureBox1.Ima ge Is Nothing Then
PictureBox1.Ima ge.Dispose()
End If

Try
PictureBox1.Ima ge = newimage
Catch Err As Exception
MsgBox(Err.Mess age)
End Try

End Sub

Now the file will be opened and locked by the picturebox, but you will
be able to do what you are trying.

HTH
Barry
On Sat, 2 Oct 2004 20:11:08 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:
Hello,
I'm trying to load different images (icons) into a PictureBox1.Ima ge.

The first image loads just fine, but the second image always returns the
error "Invalid property used."
It doesn't matter what icons are loaded. The first always shows up and
any
icons after that give me the error.

Here is the offending code:
The "DestinationPat h" variable is the full path and filename of the icon
Private Sub LoadIcon()
Dim FStream As New FileStream(Dest inationPath, FileMode.Open)
Try
PictureBox1.Ima ge = System.Drawing. Image.FromStrea m(FStream)
Catch Err As Exception
MsgBox(Err.Mess age)
End Try
FStream.Close()
End Sub
Is there something I am forgetting to close or clear?


bceggersATcomca stDOTnet


bceggersATcomca stDOTnet
Nov 21 '05 #4
When I step through it the error occurs on this line:

newimage = System.Drawing. Image.FromFile( DestinationPath )

This is the second time through. How can I tell what type of memory error
it is? I don't see anything in the error
message about GDI just the "Out of memory" text

"Barry" <bc******@castc om.com> wrote in message
news:95******** *************** *********@4ax.c om...
No, don't dispose of newimage. If you try that you will find that the
picturebox can't handle the image.

Is your out of memory error a "GDI+" error or a system error?

How many icons can you load before you get this error? I don't have
any problems with 30+ times into the subroutine.

Barry
On Sun, 3 Oct 2004 10:48:56 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:
I tried the code but after it loads a few icons it gives me an
out-of-memory
error.

I'm really beginning to "love" v b.netrightnow.S omethingsthatwe re
simple are now ridiculously hard
and other things are easier.

Do I need to dispose of the newimage after it gets placed into the
Picturebox?
"Barry" <bc******@castc om.com> wrote in message
news:f7****** *************** ***********@4ax .com...
Welcome to MS graphics!!!! (I am not a big fan of .NET graphics).

You are closing your file stream in the subroutine. Once you do that,
the picturebox cannot manipulate the image or even re-draw it.

Since the file must stay open so the picturebox can use it, try
this....

Private Sub LoadIcon()
'set up an image
Dim newimage As System.Drawing. Image
'fill from file
'but the file will stay open !!!!!
newimage = System.Drawing. Image.FromFile( lcl_filename)
'this will close the last file opened
If Not PictureBox1.Ima ge Is Nothing Then
PictureBox1.Ima ge.Dispose()
End If

Try
PictureBox1.Ima ge = newimage
Catch Err As Exception
MsgBox(Err.Mess age)
End Try

End Sub

Now the file will be opened and locked by the picturebox, but you will
be able to do what you are trying.

HTH
Barry
On Sat, 2 Oct 2004 20:11:08 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:

Hello,
I'm trying to load different images (icons) into a
PictureBox1.Ima ge.

The first image loads just fine, but the second image always returns the
error "Invalid property used."
It doesn't matter what icons are loaded. The first always shows up and
any
icons after that give me the error.

Here is the offending code:
The "DestinationPat h" variable is the full path and filename of the icon
Private Sub LoadIcon()
Dim FStream As New FileStream(Dest inationPath, FileMode.Open)
Try
PictureBox1.Ima ge = System.Drawing. Image.FromStrea m(FStream)
Catch Err As Exception
MsgBox(Err.Mess age)
End Try
FStream.Close()
End Sub
Is there something I am forgetting to close or clear?


bceggersATcomca stDOTnet


bceggersATcomca stDOTnet

Nov 21 '05 #5
Are you sure that the second file is an icon file? What happens if it
goes first (or third)? Can you just load it into the picturebox from
the IDE?

From the help file --

Image.Fromfile - Creates an Image object from the specified file.
<snip>
If the file does not have a valid image format or if GDI+ does not
support the pixel format of the file, this method throws an
OutOfMemoryExce ption exception.

It seems as if the Icon file has something different. What is it?
What is the size, resolution, pallete, etc. ?
On Sun, 3 Oct 2004 15:29:37 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:
When I step through it the error occurs on this line:

newimage = System.Drawing. Image.FromFile( DestinationPath )

This is the second time through. How can I tell what type of memory error
it is? I don't see anything in the error
message about GDI just the "Out of memory" text

"Barry" <bc******@castc om.com> wrote in message
news:95******* *************** **********@4ax. com...
No, don't dispose of newimage. If you try that you will find that the
picturebox can't handle the image.

Is your out of memory error a "GDI+" error or a system error?

How many icons can you load before you get this error? I don't have
any problems with 30+ times into the subroutine.

Barry
On Sun, 3 Oct 2004 10:48:56 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:
I tried the code but after it loads a few icons it gives me an
out-of-memory
error.

I'm really beginning to "love" v b.netrightnow.S omethingsthatwe re
simple are now ridiculously hard
and other things are easier.

Do I need to dispose of the newimage after it gets placed into the
Picturebox ?
"Barry" <bc******@castc om.com> wrote in message
news:f7***** *************** ************@4a x.com...
Welcome to MS graphics!!!! (I am not a big fan of .NET graphics).

You are closing your file stream in the subroutine. Once you do that,
the picturebox cannot manipulate the image or even re-draw it.

Since the file must stay open so the picturebox can use it, try
this....

Private Sub LoadIcon()
'set up an image
Dim newimage As System.Drawing. Image
'fill from file
'but the file will stay open !!!!!
newimage = System.Drawing. Image.FromFile( lcl_filename)
'this will close the last file opened
If Not PictureBox1.Ima ge Is Nothing Then
PictureBox1.Ima ge.Dispose()
End If

Try
PictureBox1.Ima ge = newimage
Catch Err As Exception
MsgBox(Err.Mess age)
End Try

End Sub

Now the file will be opened and locked by the picturebox, but you will
be able to do what you are trying.

HTH
Barry
On Sat, 2 Oct 2004 20:11:08 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:

>Hello,
> I'm trying to load different images (icons) into a
> PictureBox1.Ima ge.
>
>The first image loads just fine, but the second image always returns the
>error "Invalid property used."
>It doesn't matter what icons are loaded. The first always shows up and
>any
>icons after that give me the error.
>
>Here is the offending code:
>The "DestinationPat h" variable is the full path and filename of the icon
> Private Sub LoadIcon()
> Dim FStream As New FileStream(Dest inationPath, FileMode.Open)
> Try
> PictureBox1.Ima ge = System.Drawing. Image.FromStrea m(FStream)
> Catch Err As Exception
> MsgBox(Err.Mess age)
> End Try
> FStream.Close()
> End Sub
>
>
>Is there something I am forgetting to close or clear?
>
>
>

bceggersATcomca stDOTnet


bceggersATcomca stDOTnet


bceggersATcomca stDOTnet
Nov 21 '05 #6

I think you are right. One of the icons looks okay but won't load into the
image. I'll have to consider it bad and if it won't load skip it and move
to the next.
"Barry" <bc******@castc om.com> wrote in message
news:sh******** *************** *********@4ax.c om...
Are you sure that the second file is an icon file? What happens if it
goes first (or third)? Can you just load it into the picturebox from
the IDE?

From the help file --

Image.Fromfile - Creates an Image object from the specified file.
<snip>
If the file does not have a valid image format or if GDI+ does not
support the pixel format of the file, this method throws an
OutOfMemoryExce ption exception.

It seems as if the Icon file has something different. What is it?
What is the size, resolution, pallete, etc. ?
On Sun, 3 Oct 2004 15:29:37 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:
When I step through it the error occurs on this line:

newimage = System.Drawing. Image.FromFile( DestinationPath )

This is the second time through. How can I tell what type of memory error
it is? I don't see anything in the error
message about GDI just the "Out of memory" text

"Barry" <bc******@castc om.com> wrote in message
news:95****** *************** ***********@4ax .com...
No, don't dispose of newimage. If you try that you will find that the
picturebox can't handle the image.

Is your out of memory error a "GDI+" error or a system error?

How many icons can you load before you get this error? I don't have
any problems with 30+ times into the subroutine.

Barry
On Sun, 3 Oct 2004 10:48:56 -0500, "Patrick Dugan"
<pa******@netin s.net> wrote:

I tried the code but after it loads a few icons it gives me an
out-of-memory
error.

I'm really beginning to "love" v b.netrightnow.S omethingsthatwe re
simple are now ridiculously hard
and other things are easier.

Do I need to dispose of the newimage after it gets placed into the
Picturebo x?
"Barry" <bc******@castc om.com> wrote in message
news:f7**** *************** *************@4 ax.com...
> Welcome to MS graphics!!!! (I am not a big fan of .NET graphics).
>
> You are closing your file stream in the subroutine. Once you do that,
> the picturebox cannot manipulate the image or even re-draw it.
>
> Since the file must stay open so the picturebox can use it, try
> this....
>
> Private Sub LoadIcon()
> 'set up an image
> Dim newimage As System.Drawing. Image
> 'fill from file
> 'but the file will stay open !!!!!
> newimage = System.Drawing. Image.FromFile( lcl_filename)
> 'this will close the last file opened
> If Not PictureBox1.Ima ge Is Nothing Then
> PictureBox1.Ima ge.Dispose()
> End If
>
> Try
> PictureBox1.Ima ge = newimage
> Catch Err As Exception
> MsgBox(Err.Mess age)
> End Try
>
> End Sub
>
> Now the file will be opened and locked by the picturebox, but you will
> be able to do what you are trying.
>
> HTH
> Barry
> On Sat, 2 Oct 2004 20:11:08 -0500, "Patrick Dugan"
> <pa******@netin s.net> wrote:
>
>>Hello,
>> I'm trying to load different images (icons) into a
>> PictureBox1.Ima ge.
>>
>>The first image loads just fine, but the second image always returns
>>the
>>error "Invalid property used."
>>It doesn't matter what icons are loaded. The first always shows up
>>and
>>any
>>icons after that give me the error.
>>
>>Here is the offending code:
>>The "DestinationPat h" variable is the full path and filename of the
>>icon
>> Private Sub LoadIcon()
>> Dim FStream As New FileStream(Dest inationPath, FileMode.Open)
>> Try
>> PictureBox1.Ima ge =
>> System.Drawing. Image.FromStrea m(FStream)
>> Catch Err As Exception
>> MsgBox(Err.Mess age)
>> End Try
>> FStream.Close()
>> End Sub
>>
>>
>>Is there something I am forgetting to close or clear?
>>
>>
>>
>
> bceggersATcomca stDOTnet
bceggersATcomca stDOTnet


bceggersATcomca stDOTnet

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2029
by: vincent wehren | last post by:
Hi, Trying to grasp Py_NewInterpreter()in a simple app embedding Python, I was wondering why the following gives me an error: int main() { PyThreadState *tstate; Py_Initialize();
3
3013
by: Stephen Poley | last post by:
Could some kind soul explain the errors and warnings that the W3C CSS validator generates for page: http://www.atlis.nl/testsite/nl/ Results at: http://tinyurl.com/5pxqx The error "Invalid number : borderParse Error - " may be due to something I've done, but I'm blowed if I can see what. While the warning "property display doesn't exist for media" has me baffled.
9
1966
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 Basic .Net application. I have researched MSDN for help and found the example article 321900 (see below) and set up a test and everything works fine when I use SQL Server 2000 but when I modify the code and use data from Access 2000 using an...
7
2658
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 controls, I get this error. This is how it goes : <code> byte bImage1 = (byte)datasetImageList.Tables.Rows; System.IO.MemoryStream ms = new MemoryStream(bImage1, 0, bImage1.Length); this.lblRunImage.Image = System.Drawing.Image.FromStream(ms); //...
0
1824
by: Simon Harris | last post by:
I'm trying to access a password protected web service. My code is as follows: Dim BS7666 As New bs7666.BS7666 'New instance of my web service Dim CredCache As CredentialCache = New CredentialCache Dim WebSvcURL As System.Uri = New System.Uri(BS7666.Url) CredCache.Add(WebSvcURL, "Basic", New NetworkCredential("USERNAME", "PASSWORD", "DOMAIN")) 'This is the line it fails on BS7666.Credentials = CredCache Dim DataSet_bs7666 As New...
3
2587
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 As New SaveFileDialog Dim strCn As String = "Data Source=DATABASE\BARCA;" & _ "Initial Catalog=MIS;Integrated Security=SSPI" Dim cn As SqlConnection = New SqlConnection(strCn) Dim fs As IO.FileStream
4
3060
by: escristian | last post by:
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.
1
3173
by: imranabdulaziz | last post by:
Dear All, I am using sql2005. i am writing stored procedure to save various master data . I recognize master by @type (input verible) and assign it to @mst veriable then based on @mst no I perform saving task . I created sp . now I am trying to execute then I am getting error “Invalid object name 'SizeMst'. “ I am running this query from its database. Stored perocedure is Alter procedure . @type int ,
0
9487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.