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 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 "DestinationPath" variable is the full path and filename of the icon
Private Sub LoadIcon()
Dim FStream As New FileStream(DestinationPath, FileMode.Open)
Try
PictureBox1.Image = System.Drawing.Image.FromStream(FStream)
Catch Err As Exception
MsgBox(Err.Message)
End Try
FStream.Close()
End Sub
Is there something I am forgetting to close or clear? 6 1950
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.Image Is Nothing Then
PictureBox1.Image.Dispose()
End If
Try
PictureBox1.Image = newimage
Catch Err As Exception
MsgBox(Err.Message)
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******@netins.net> wrote: 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 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 "DestinationPath" variable is the full path and filename of the icon Private Sub LoadIcon() Dim FStream As New FileStream(DestinationPath, FileMode.Open) Try PictureBox1.Image = System.Drawing.Image.FromStream(FStream) Catch Err As Exception MsgBox(Err.Message) End Try FStream.Close() End Sub
Is there something I am forgetting to close or clear?
bceggersATcomcastDOTnet
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******@castcom.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.Image Is Nothing Then PictureBox1.Image.Dispose() End If
Try PictureBox1.Image = newimage Catch Err As Exception MsgBox(Err.Message) 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******@netins.net> wrote:
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 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 "DestinationPath" variable is the full path and filename of the icon Private Sub LoadIcon() Dim FStream As New FileStream(DestinationPath, FileMode.Open) Try PictureBox1.Image = System.Drawing.Image.FromStream(FStream) Catch Err As Exception MsgBox(Err.Message) End Try FStream.Close() End Sub
Is there something I am forgetting to close or clear?
bceggersATcomcastDOTnet
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******@netins.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.Somethingsthatwere 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******@castcom.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.Image Is Nothing Then PictureBox1.Image.Dispose() End If
Try PictureBox1.Image = newimage Catch Err As Exception MsgBox(Err.Message) 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******@netins.net> wrote:
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 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 "DestinationPath" variable is the full path and filename of the icon Private Sub LoadIcon() Dim FStream As New FileStream(DestinationPath, FileMode.Open) Try PictureBox1.Image = System.Drawing.Image.FromStream(FStream) Catch Err As Exception MsgBox(Err.Message) End Try FStream.Close() End Sub
Is there something I am forgetting to close or clear?
bceggersATcomcastDOTnet
bceggersATcomcastDOTnet
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******@castcom.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******@netins.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.Somethingsthatwere 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******@castcom.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.Image Is Nothing Then PictureBox1.Image.Dispose() End If
Try PictureBox1.Image = newimage Catch Err As Exception MsgBox(Err.Message) 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******@netins.net> wrote:
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 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 "DestinationPath" variable is the full path and filename of the icon Private Sub LoadIcon() Dim FStream As New FileStream(DestinationPath, FileMode.Open) Try PictureBox1.Image = System.Drawing.Image.FromStream(FStream) Catch Err As Exception MsgBox(Err.Message) End Try FStream.Close() End Sub
Is there something I am forgetting to close or clear?
bceggersATcomcastDOTnet
bceggersATcomcastDOTnet
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
OutOfMemoryException 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******@netins.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******@castcom.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******@netins.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.Somethingsthatwere 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******@castcom.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.Image Is Nothing Then PictureBox1.Image.Dispose() End If
Try PictureBox1.Image = newimage Catch Err As Exception MsgBox(Err.Message) 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******@netins.net> wrote:
>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 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 "DestinationPath" variable is the full path and filename of the icon > Private Sub LoadIcon() > Dim FStream As New FileStream(DestinationPath, FileMode.Open) > Try > PictureBox1.Image = System.Drawing.Image.FromStream(FStream) > Catch Err As Exception > MsgBox(Err.Message) > End Try > FStream.Close() > End Sub > > >Is there something I am forgetting to close or clear? > > >
bceggersATcomcastDOTnet
bceggersATcomcastDOTnet
bceggersATcomcastDOTnet
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******@castcom.com> wrote in message
news:sh********************************@4ax.com... 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 OutOfMemoryException 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******@netins.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******@castcom.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******@netins.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.Somethingsthatwere 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******@castcom.com> wrote in message news:f7********************************@4ax.co m... > 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.Image Is Nothing Then > PictureBox1.Image.Dispose() > End If > > Try > PictureBox1.Image = newimage > Catch Err As Exception > MsgBox(Err.Message) > 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******@netins.net> wrote: > >>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 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 "DestinationPath" variable is the full path and filename of the >>icon >> Private Sub LoadIcon() >> Dim FStream As New FileStream(DestinationPath, FileMode.Open) >> Try >> PictureBox1.Image = >> System.Drawing.Image.FromStream(FStream) >> Catch Err As Exception >> MsgBox(Err.Message) >> End Try >> FStream.Close() >> End Sub >> >> >>Is there something I am forgetting to close or clear? >> >> >> > > bceggersATcomcastDOTnet
bceggersATcomcastDOTnet
bceggersATcomcastDOTnet This discussion thread is closed Replies have been disabled for this discussion. Similar topics
reply
views
Thread by vincent wehren |
last post: by
|
3 posts
views
Thread by Stephen Poley |
last post: by
|
9 posts
views
Thread by Wally |
last post: by
|
7 posts
views
Thread by cnu |
last post: by
|
reply
views
Thread by Simon Harris |
last post: by
|
3 posts
views
Thread by Arnold |
last post: by
|
4 posts
views
Thread by escristian |
last post: by
| | | | | | | | | | | |