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

image.fromstream error

P: n/a
hey all,

first time vb.net 2005 user, after sticking vb6 out for a long time...

anyway, using this code
======================
Dim FS As FileStream = File.OpenRead(Filename)
Dim theImage As Image
Try
theImage = Image.FromStream(FS, False, False)
Catch ex As Exception
Debug.Print(FS.Name)
FS.Close()
Exit Sub
End Try

Dim Width As Integer = theImage.Width
Dim Height As Integer = theImage.Height
theImage.Dispose()
FS.Close()
========================

works fine except for on a handful of images. all of the images are tif files that open
in evey application i have ever tried to open them in. i'm just getting the width and
height without loading the entire image into memory (they are about 150 MB each and there
are thousands of them). the debug window shows:

"A first chance exception of type 'System.ArgumentException' occurred in
System.Drawing.dll"

on the "bad" ones and if i step into, the error i get is "Parameter not valid" at the

theImage = Image.FromStream(FS, False, False)

line. what could be causing this? the code works for 99.9% of the images, but not for a
handful that are otherwise perfectly fine.

thanks,
lance
Nov 23 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Dear Lance,

I don't know if it will help you with answering your question, but
Image.FromStream() throws an ArgumentException when the stream does not have
a valid image format (see the docs for this). Perhaps this is the case. If I
were you, I would try to see if there are any differences in the 'good' and
the 'bad' files (also read-only or not). Also, try to change the last
parameter to true instead of false, as this parameter will validate the
'ImageData'.

Hope this helps you,

Michel van den Berg

"Lance" <nu***@business.com> schreef in bericht
news:ei*************@TK2MSFTNGP10.phx.gbl...
hey all,

first time vb.net 2005 user, after sticking vb6 out for a long time...

anyway, using this code
======================
Dim FS As FileStream = File.OpenRead(Filename)
Dim theImage As Image
Try
theImage = Image.FromStream(FS, False, False)
Catch ex As Exception
Debug.Print(FS.Name)
FS.Close()
Exit Sub
End Try

Dim Width As Integer = theImage.Width
Dim Height As Integer = theImage.Height
theImage.Dispose()
FS.Close()
========================

works fine except for on a handful of images. all of the images are tif
files that open in evey application i have ever tried to open them in.
i'm just getting the width and height without loading the entire image
into memory (they are about 150 MB each and there are thousands of them).
the debug window shows:

"A first chance exception of type 'System.ArgumentException' occurred
in System.Drawing.dll"

on the "bad" ones and if i step into, the error i get is "Parameter not
valid" at the

theImage = Image.FromStream(FS, False, False)

line. what could be causing this? the code works for 99.9% of the
images, but not for a handful that are otherwise perfectly fine.

thanks,
lance

Nov 23 '05 #2

P: n/a
i should have mentioned that i had already tried setting the third parameter to true. the
same thing happens, unfortunately. none of the file are read only, or opened already.
they were all actually created by the same software using the same parameters.

the handful that return these errors open fine in every other tag viewer and image
application. that's what is so frustrating.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
Dear Lance,

I don't know if it will help you with answering your question, but Image.FromStream()
throws an ArgumentException when the stream does not have a valid image format (see the
docs for this). Perhaps this is the case. If I were you, I would try to see if there are
any differences in the 'good' and the 'bad' files (also read-only or not). Also, try to
change the last parameter to true instead of false, as this parameter will validate the
'ImageData'.

Hope this helps you,

Michel van den Berg

"Lance" <nu***@business.com> schreef in bericht
news:ei*************@TK2MSFTNGP10.phx.gbl...
hey all,

first time vb.net 2005 user, after sticking vb6 out for a long time...

anyway, using this code
======================
Dim FS As FileStream = File.OpenRead(Filename)
Dim theImage As Image
Try
theImage = Image.FromStream(FS, False, False)
Catch ex As Exception
Debug.Print(FS.Name)
FS.Close()
Exit Sub
End Try

Dim Width As Integer = theImage.Width
Dim Height As Integer = theImage.Height
theImage.Dispose()
FS.Close()
========================

works fine except for on a handful of images. all of the images are tif files that
open in evey application i have ever tried to open them in. i'm just getting the width
and height without loading the entire image into memory (they are about 150 MB each and
there are thousands of them). the debug window shows:

"A first chance exception of type 'System.ArgumentException' occurred in
System.Drawing.dll"

on the "bad" ones and if i step into, the error i get is "Parameter not valid" at the

theImage = Image.FromStream(FS, False, False)

line. what could be causing this? the code works for 99.9% of the images, but not for
a handful that are otherwise perfectly fine.

thanks,
lance


Nov 23 '05 #3

P: n/a
Dear Lance,

Is the code your posted the (real) code as implemented in your app, or do
you, for instance, alter or dispose the filestream?

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <nu***@business.com> schreef in bericht
news:OC****************@TK2MSFTNGP09.phx.gbl...
i should have mentioned that i had already tried setting the third
parameter to true. the same thing happens, unfortunately. none of the
file are read only, or opened already. they were all actually created by
the same software using the same parameters.

the handful that return these errors open fine in every other tag viewer
and image application. that's what is so frustrating.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
Dear Lance,

I don't know if it will help you with answering your question, but
Image.FromStream() throws an ArgumentException when the stream does not
have a valid image format (see the docs for this). Perhaps this is the
case. If I were you, I would try to see if there are any differences in
the 'good' and the 'bad' files (also read-only or not). Also, try to
change the last parameter to true instead of false, as this parameter
will validate the 'ImageData'.

Hope this helps you,

Michel van den Berg

"Lance" <nu***@business.com> schreef in bericht
news:ei*************@TK2MSFTNGP10.phx.gbl...
hey all,

first time vb.net 2005 user, after sticking vb6 out for a long time...

anyway, using this code
======================
Dim FS As FileStream = File.OpenRead(Filename)
Dim theImage As Image
Try
theImage = Image.FromStream(FS, False, False)
Catch ex As Exception
Debug.Print(FS.Name)
FS.Close()
Exit Sub
End Try

Dim Width As Integer = theImage.Width
Dim Height As Integer = theImage.Height
theImage.Dispose()
FS.Close()
========================

works fine except for on a handful of images. all of the images are tif
files that open in evey application i have ever tried to open them in.
i'm just getting the width and height without loading the entire image
into memory (they are about 150 MB each and there are thousands of
them). the debug window shows:

"A first chance exception of type 'System.ArgumentException' occurred
in System.Drawing.dll"

on the "bad" ones and if i step into, the error i get is "Parameter not
valid" at the

theImage = Image.FromStream(FS, False, False)

line. what could be causing this? the code works for 99.9% of the
images, but not for a handful that are otherwise perfectly fine.

thanks,
lance



Nov 23 '05 #4

P: n/a
michel,

that's pretty much the code, yeah. i don't alter the stream - if by "alter"
you mean change the image in any way. i'm just opening it long enough to be
able to get the width and height of a tif file. please let me know if i
missunderstood your question.

by the way, the reason the third parameter is set to false is so that this
can be done very quickly, as the are thousands of images to extract the
dimensions from. as i mentioned, though, it doesn't matter whether the
parameter is set to true, as it still produces the same error on the same
images.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
Dear Lance,

Is the code your posted the (real) code as implemented in your app, or do
you, for instance, alter or dispose the filestream?

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <nu***@business.com> schreef in bericht
news:OC****************@TK2MSFTNGP09.phx.gbl...
i should have mentioned that i had already tried setting the third
parameter to true. the same thing happens, unfortunately. none of the
file are read only, or opened already. they were all actually created by
the same software using the same parameters.

the handful that return these errors open fine in every other tag viewer
and image application. that's what is so frustrating.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
Dear Lance,

I don't know if it will help you with answering your question, but
Image.FromStream() throws an ArgumentException when the stream does not
have a valid image format (see the docs for this). Perhaps this is the
case. If I were you, I would try to see if there are any differences in
the 'good' and the 'bad' files (also read-only or not). Also, try to
change the last parameter to true instead of false, as this parameter
will validate the 'ImageData'.

Hope this helps you,

Michel van den Berg

"Lance" <nu***@business.com> schreef in bericht
news:ei*************@TK2MSFTNGP10.phx.gbl...
hey all,

first time vb.net 2005 user, after sticking vb6 out for a long time...

anyway, using this code
======================
Dim FS As FileStream = File.OpenRead(Filename)
Dim theImage As Image
Try
theImage = Image.FromStream(FS, False, False)
Catch ex As Exception
Debug.Print(FS.Name)
FS.Close()
Exit Sub
End Try

Dim Width As Integer = theImage.Width
Dim Height As Integer = theImage.Height
theImage.Dispose()
FS.Close()
========================

works fine except for on a handful of images. all of the images are
tif files that open in evey application i have ever tried to open them
in. i'm just getting the width and height without loading the entire
image into memory (they are about 150 MB each and there are thousands
of them). the debug window shows:

"A first chance exception of type 'System.ArgumentException'
occurred in System.Drawing.dll"

on the "bad" ones and if i step into, the error i get is "Parameter not
valid" at the

theImage = Image.FromStream(FS, False, False)

line. what could be causing this? the code works for 99.9% of the
images, but not for a handful that are otherwise perfectly fine.

thanks,
lance



Nov 23 '05 #5

P: n/a
Dear Lance,

Could you perhaps send me some good and bad images, so that I may try the
code for myself? You can send it to my e-mail address.

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in bericht
news:O0**************@TK2MSFTNGP12.phx.gbl...
michel,

that's pretty much the code, yeah. i don't alter the stream - if by
"alter" you mean change the image in any way. i'm just opening it long
enough to be able to get the width and height of a tif file. please let
me know if i missunderstood your question.

by the way, the reason the third parameter is set to false is so that this
can be done very quickly, as the are thousands of images to extract the
dimensions from. as i mentioned, though, it doesn't matter whether the
parameter is set to true, as it still produces the same error on the same
images.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
Dear Lance,

Is the code your posted the (real) code as implemented in your app, or do
you, for instance, alter or dispose the filestream?

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <nu***@business.com> schreef in bericht
news:OC****************@TK2MSFTNGP09.phx.gbl...
i should have mentioned that i had already tried setting the third
parameter to true. the same thing happens, unfortunately. none of the
file are read only, or opened already. they were all actually created by
the same software using the same parameters.

the handful that return these errors open fine in every other tag viewer
and image application. that's what is so frustrating.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
Dear Lance,

I don't know if it will help you with answering your question, but
Image.FromStream() throws an ArgumentException when the stream does not
have a valid image format (see the docs for this). Perhaps this is the
case. If I were you, I would try to see if there are any differences in
the 'good' and the 'bad' files (also read-only or not). Also, try to
change the last parameter to true instead of false, as this parameter
will validate the 'ImageData'.

Hope this helps you,

Michel van den Berg

"Lance" <nu***@business.com> schreef in bericht
news:ei*************@TK2MSFTNGP10.phx.gbl...
> hey all,
>
> first time vb.net 2005 user, after sticking vb6 out for a long time...
>
> anyway, using this code
> ======================
> Dim FS As FileStream = File.OpenRead(Filename)
> Dim theImage As Image
> Try
> theImage = Image.FromStream(FS, False, False)
> Catch ex As Exception
> Debug.Print(FS.Name)
> FS.Close()
> Exit Sub
> End Try
>
> Dim Width As Integer = theImage.Width
> Dim Height As Integer = theImage.Height
> theImage.Dispose()
> FS.Close()
> ========================
>
> works fine except for on a handful of images. all of the images are
> tif files that open in evey application i have ever tried to open them
> in. i'm just getting the width and height without loading the entire
> image into memory (they are about 150 MB each and there are thousands
> of them). the debug window shows:
>
> "A first chance exception of type 'System.ArgumentException'
> occurred in System.Drawing.dll"
>
> on the "bad" ones and if i step into, the error i get is "Parameter
> not valid" at the
>
> theImage = Image.FromStream(FS, False, False)
>
> line. what could be causing this? the code works for 99.9% of the
> images, but not for a handful that are otherwise perfectly fine.
>
> thanks,
> lance
>
>



Nov 23 '05 #6

P: n/a
i'll zip up a good one and a "bad" one and upload it to our ftp site and
email you the address. these are large images, but the ftp server
connection is pretty fast, so if you've got broadband, they will only take a
few minutes to download.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dear Lance,

Could you perhaps send me some good and bad images, so that I may try the
code for myself? You can send it to my e-mail address.

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in
bericht news:O0**************@TK2MSFTNGP12.phx.gbl...
michel,

that's pretty much the code, yeah. i don't alter the stream - if by
"alter" you mean change the image in any way. i'm just opening it long
enough to be able to get the width and height of a tif file. please let
me know if i missunderstood your question.

by the way, the reason the third parameter is set to false is so that
this can be done very quickly, as the are thousands of images to extract
the dimensions from. as i mentioned, though, it doesn't matter whether
the parameter is set to true, as it still produces the same error on the
same images.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
Dear Lance,

Is the code your posted the (real) code as implemented in your app, or
do you, for instance, alter or dispose the filestream?

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <nu***@business.com> schreef in bericht
news:OC****************@TK2MSFTNGP09.phx.gbl...
i should have mentioned that i had already tried setting the third
parameter to true. the same thing happens, unfortunately. none of the
file are read only, or opened already. they were all actually created by
the same software using the same parameters.

the handful that return these errors open fine in every other tag
viewer and image application. that's what is so frustrating.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
> Dear Lance,
>
> I don't know if it will help you with answering your question, but
> Image.FromStream() throws an ArgumentException when the stream does
> not have a valid image format (see the docs for this). Perhaps this is
> the case. If I were you, I would try to see if there are any
> differences in the 'good' and the 'bad' files (also read-only or not).
> Also, try to change the last parameter to true instead of false, as
> this parameter will validate the 'ImageData'.
>
> Hope this helps you,
>
> Michel van den Berg
>
> "Lance" <nu***@business.com> schreef in bericht
> news:ei*************@TK2MSFTNGP10.phx.gbl...
>> hey all,
>>
>> first time vb.net 2005 user, after sticking vb6 out for a long
>> time...
>>
>> anyway, using this code
>> ======================
>> Dim FS As FileStream = File.OpenRead(Filename)
>> Dim theImage As Image
>> Try
>> theImage = Image.FromStream(FS, False, False)
>> Catch ex As Exception
>> Debug.Print(FS.Name)
>> FS.Close()
>> Exit Sub
>> End Try
>>
>> Dim Width As Integer = theImage.Width
>> Dim Height As Integer = theImage.Height
>> theImage.Dispose()
>> FS.Close()
>> ========================
>>
>> works fine except for on a handful of images. all of the images are
>> tif files that open in evey application i have ever tried to open
>> them in. i'm just getting the width and height without loading the
>> entire image into memory (they are about 150 MB each and there are
>> thousands of them). the debug window shows:
>>
>> "A first chance exception of type 'System.ArgumentException'
>> occurred in System.Drawing.dll"
>>
>> on the "bad" ones and if i step into, the error i get is "Parameter
>> not valid" at the
>>
>> theImage = Image.FromStream(FS, False, False)
>>
>> line. what could be causing this? the code works for 99.9% of the
>> images, but not for a handful that are otherwise perfectly fine.
>>
>> thanks,
>> lance
>>
>>
>
>



Nov 23 '05 #7

P: n/a
sent...

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dear Lance,

Could you perhaps send me some good and bad images, so that I may try the
code for myself? You can send it to my e-mail address.

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in
bericht news:O0**************@TK2MSFTNGP12.phx.gbl...
michel,

that's pretty much the code, yeah. i don't alter the stream - if by
"alter" you mean change the image in any way. i'm just opening it long
enough to be able to get the width and height of a tif file. please let
me know if i missunderstood your question.

by the way, the reason the third parameter is set to false is so that
this can be done very quickly, as the are thousands of images to extract
the dimensions from. as i mentioned, though, it doesn't matter whether
the parameter is set to true, as it still produces the same error on the
same images.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
Dear Lance,

Is the code your posted the (real) code as implemented in your app, or
do you, for instance, alter or dispose the filestream?

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <nu***@business.com> schreef in bericht
news:OC****************@TK2MSFTNGP09.phx.gbl...
i should have mentioned that i had already tried setting the third
parameter to true. the same thing happens, unfortunately. none of the
file are read only, or opened already. they were all actually created by
the same software using the same parameters.

the handful that return these errors open fine in every other tag
viewer and image application. that's what is so frustrating.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
> Dear Lance,
>
> I don't know if it will help you with answering your question, but
> Image.FromStream() throws an ArgumentException when the stream does
> not have a valid image format (see the docs for this). Perhaps this is
> the case. If I were you, I would try to see if there are any
> differences in the 'good' and the 'bad' files (also read-only or not).
> Also, try to change the last parameter to true instead of false, as
> this parameter will validate the 'ImageData'.
>
> Hope this helps you,
>
> Michel van den Berg
>
> "Lance" <nu***@business.com> schreef in bericht
> news:ei*************@TK2MSFTNGP10.phx.gbl...
>> hey all,
>>
>> first time vb.net 2005 user, after sticking vb6 out for a long
>> time...
>>
>> anyway, using this code
>> ======================
>> Dim FS As FileStream = File.OpenRead(Filename)
>> Dim theImage As Image
>> Try
>> theImage = Image.FromStream(FS, False, False)
>> Catch ex As Exception
>> Debug.Print(FS.Name)
>> FS.Close()
>> Exit Sub
>> End Try
>>
>> Dim Width As Integer = theImage.Width
>> Dim Height As Integer = theImage.Height
>> theImage.Dispose()
>> FS.Close()
>> ========================
>>
>> works fine except for on a handful of images. all of the images are
>> tif files that open in evey application i have ever tried to open
>> them in. i'm just getting the width and height without loading the
>> entire image into memory (they are about 150 MB each and there are
>> thousands of them). the debug window shows:
>>
>> "A first chance exception of type 'System.ArgumentException'
>> occurred in System.Drawing.dll"
>>
>> on the "bad" ones and if i step into, the error i get is "Parameter
>> not valid" at the
>>
>> theImage = Image.FromStream(FS, False, False)
>>
>> line. what could be causing this? the code works for 99.9% of the
>> images, but not for a handful that are otherwise perfectly fine.
>>
>> thanks,
>> lance
>>
>>
>
>



Nov 23 '05 #8

P: n/a
Dear Lance,

As I suspected is your problem the picture itself. To be more precise:
within its compression it is using.
The working picture has no compression whereas the bad picture has. GDI+
does not support (that) compression with TIF files.
To verify my statement: I resaved the bad image without compression and it
now works.
So, I suggest, if possible, to alter the program generating these images to
output without compression.

Hope it helps,

Michel van den Berg

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in bericht
news:OB*************@TK2MSFTNGP10.phx.gbl...
sent...

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dear Lance,

Could you perhaps send me some good and bad images, so that I may try the
code for myself? You can send it to my e-mail address.

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in
bericht news:O0**************@TK2MSFTNGP12.phx.gbl...
michel,

that's pretty much the code, yeah. i don't alter the stream - if by
"alter" you mean change the image in any way. i'm just opening it long
enough to be able to get the width and height of a tif file. please let
me know if i missunderstood your question.

by the way, the reason the third parameter is set to false is so that
this can be done very quickly, as the are thousands of images to extract
the dimensions from. as i mentioned, though, it doesn't matter whether
the parameter is set to true, as it still produces the same error on the
same images.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
Dear Lance,

Is the code your posted the (real) code as implemented in your app, or
do you, for instance, alter or dispose the filestream?

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <nu***@business.com> schreef in bericht
news:OC****************@TK2MSFTNGP09.phx.gbl...
>i should have mentioned that i had already tried setting the third
>parameter to true. the same thing happens, unfortunately. none of the
>file are read only, or opened already. they were all actually created
>by the same software using the same parameters.
>
> the handful that return these errors open fine in every other tag
> viewer and image application. that's what is so frustrating.
>
> lance
>
>
>
> "Michel van den Berg" <mv*@promontis.nl> wrote in message
> news:e2**************@TK2MSFTNGP14.phx.gbl...
>> Dear Lance,
>>
>> I don't know if it will help you with answering your question, but
>> Image.FromStream() throws an ArgumentException when the stream does
>> not have a valid image format (see the docs for this). Perhaps this
>> is the case. If I were you, I would try to see if there are any
>> differences in the 'good' and the 'bad' files (also read-only or
>> not). Also, try to change the last parameter to true instead of
>> false, as this parameter will validate the 'ImageData'.
>>
>> Hope this helps you,
>>
>> Michel van den Berg
>>
>> "Lance" <nu***@business.com> schreef in bericht
>> news:ei*************@TK2MSFTNGP10.phx.gbl...
>>> hey all,
>>>
>>> first time vb.net 2005 user, after sticking vb6 out for a long
>>> time...
>>>
>>> anyway, using this code
>>> ======================
>>> Dim FS As FileStream = File.OpenRead(Filename)
>>> Dim theImage As Image
>>> Try
>>> theImage = Image.FromStream(FS, False, False)
>>> Catch ex As Exception
>>> Debug.Print(FS.Name)
>>> FS.Close()
>>> Exit Sub
>>> End Try
>>>
>>> Dim Width As Integer = theImage.Width
>>> Dim Height As Integer = theImage.Height
>>> theImage.Dispose()
>>> FS.Close()
>>> ========================
>>>
>>> works fine except for on a handful of images. all of the images are
>>> tif files that open in evey application i have ever tried to open
>>> them in. i'm just getting the width and height without loading the
>>> entire image into memory (they are about 150 MB each and there are
>>> thousands of them). the debug window shows:
>>>
>>> "A first chance exception of type 'System.ArgumentException'
>>> occurred in System.Drawing.dll"
>>>
>>> on the "bad" ones and if i step into, the error i get is "Parameter
>>> not valid" at the
>>>
>>> theImage = Image.FromStream(FS, False, False)
>>>
>>> line. what could be causing this? the code works for 99.9% of the
>>> images, but not for a handful that are otherwise perfectly fine.
>>>
>>> thanks,
>>> lance
>>>
>>>
>>
>>
>
>



Nov 23 '05 #9

P: n/a
thanks so much for looking into this. i was assured by the image supplier that all of the
images were created using the same parameters. after your reply, i used a tag view and
can now see that the "software" key is indeed different in the bad images, as is the
compression of course.

i guess this means i'm going to need to write my own tif image info class that doesn't
make use of GDI+.

thanks,
lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Dear Lance,

As I suspected is your problem the picture itself. To be more precise: within its
compression it is using.
The working picture has no compression whereas the bad picture has. GDI+ does not
support (that) compression with TIF files.
To verify my statement: I resaved the bad image without compression and it now works.
So, I suggest, if possible, to alter the program generating these images to output
without compression.

Hope it helps,

Michel van den Berg

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in bericht
news:OB*************@TK2MSFTNGP10.phx.gbl...
sent...

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dear Lance,

Could you perhaps send me some good and bad images, so that I may try the code for
myself? You can send it to my e-mail address.

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in bericht
news:O0**************@TK2MSFTNGP12.phx.gbl...
michel,

that's pretty much the code, yeah. i don't alter the stream - if by "alter" you mean
change the image in any way. i'm just opening it long enough to be able to get the
width and height of a tif file. please let me know if i missunderstood your
question.

by the way, the reason the third parameter is set to false is so that this can be
done very quickly, as the are thousands of images to extract the dimensions from. as
i mentioned, though, it doesn't matter whether the parameter is set to true, as it
still produces the same error on the same images.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
> Dear Lance,
>
> Is the code your posted the (real) code as implemented in your app, or do you, for
> instance, alter or dispose the filestream?
>
> Michel van den Berg
> --
> == Remove nospam to email me ==
>
> "Lance" <nu***@business.com> schreef in bericht
> news:OC****************@TK2MSFTNGP09.phx.gbl...
>>i should have mentioned that i had already tried setting the third parameter to
>>true. the same thing happens, unfortunately. none of the file are read only, or
>>opened already. they were all actually created by the same software using the same
>>parameters.
>>
>> the handful that return these errors open fine in every other tag viewer and image
>> application. that's what is so frustrating.
>>
>> lance
>>
>>
>>
>> "Michel van den Berg" <mv*@promontis.nl> wrote in message
>> news:e2**************@TK2MSFTNGP14.phx.gbl...
>>> Dear Lance,
>>>
>>> I don't know if it will help you with answering your question, but
>>> Image.FromStream() throws an ArgumentException when the stream does not have a
>>> valid image format (see the docs for this). Perhaps this is the case. If I were
>>> you, I would try to see if there are any differences in the 'good' and the 'bad'
>>> files (also read-only or not). Also, try to change the last parameter to true
>>> instead of false, as this parameter will validate the 'ImageData'.
>>>
>>> Hope this helps you,
>>>
>>> Michel van den Berg
>>>
>>> "Lance" <nu***@business.com> schreef in bericht
>>> news:ei*************@TK2MSFTNGP10.phx.gbl...
>>>> hey all,
>>>>
>>>> first time vb.net 2005 user, after sticking vb6 out for a long time...
>>>>
>>>> anyway, using this code
>>>> ======================
>>>> Dim FS As FileStream = File.OpenRead(Filename)
>>>> Dim theImage As Image
>>>> Try
>>>> theImage = Image.FromStream(FS, False, False)
>>>> Catch ex As Exception
>>>> Debug.Print(FS.Name)
>>>> FS.Close()
>>>> Exit Sub
>>>> End Try
>>>>
>>>> Dim Width As Integer = theImage.Width
>>>> Dim Height As Integer = theImage.Height
>>>> theImage.Dispose()
>>>> FS.Close()
>>>> ========================
>>>>
>>>> works fine except for on a handful of images. all of the images are tif files
>>>> that open in evey application i have ever tried to open them in. i'm just getting
>>>> the width and height without loading the entire image into memory (they are about
>>>> 150 MB each and there are thousands of them). the debug window shows:
>>>>
>>>> "A first chance exception of type 'System.ArgumentException' occurred in
>>>> System.Drawing.dll"
>>>>
>>>> on the "bad" ones and if i step into, the error i get is "Parameter not valid" at
>>>> the
>>>>
>>>> theImage = Image.FromStream(FS, False, False)
>>>>
>>>> line. what could be causing this? the code works for 99.9% of the images, but
>>>> not for a handful that are otherwise perfectly fine.
>>>>
>>>> thanks,
>>>> lance
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Nov 23 '05 #10

P: n/a
michel,

interestingly, there are some packbit compressed tif files that seem to work.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Dear Lance,

As I suspected is your problem the picture itself. To be more precise: within its
compression it is using.
The working picture has no compression whereas the bad picture has. GDI+ does not
support (that) compression with TIF files.
To verify my statement: I resaved the bad image without compression and it now works.
So, I suggest, if possible, to alter the program generating these images to output
without compression.

Hope it helps,

Michel van den Berg

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in bericht
news:OB*************@TK2MSFTNGP10.phx.gbl...
sent...

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dear Lance,

Could you perhaps send me some good and bad images, so that I may try the code for
myself? You can send it to my e-mail address.

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in bericht
news:O0**************@TK2MSFTNGP12.phx.gbl...
michel,

that's pretty much the code, yeah. i don't alter the stream - if by "alter" you mean
change the image in any way. i'm just opening it long enough to be able to get the
width and height of a tif file. please let me know if i missunderstood your
question.

by the way, the reason the third parameter is set to false is so that this can be
done very quickly, as the are thousands of images to extract the dimensions from. as
i mentioned, though, it doesn't matter whether the parameter is set to true, as it
still produces the same error on the same images.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
> Dear Lance,
>
> Is the code your posted the (real) code as implemented in your app, or do you, for
> instance, alter or dispose the filestream?
>
> Michel van den Berg
> --
> == Remove nospam to email me ==
>
> "Lance" <nu***@business.com> schreef in bericht
> news:OC****************@TK2MSFTNGP09.phx.gbl...
>>i should have mentioned that i had already tried setting the third parameter to
>>true. the same thing happens, unfortunately. none of the file are read only, or
>>opened already. they were all actually created by the same software using the same
>>parameters.
>>
>> the handful that return these errors open fine in every other tag viewer and image
>> application. that's what is so frustrating.
>>
>> lance
>>
>>
>>
>> "Michel van den Berg" <mv*@promontis.nl> wrote in message
>> news:e2**************@TK2MSFTNGP14.phx.gbl...
>>> Dear Lance,
>>>
>>> I don't know if it will help you with answering your question, but
>>> Image.FromStream() throws an ArgumentException when the stream does not have a
>>> valid image format (see the docs for this). Perhaps this is the case. If I were
>>> you, I would try to see if there are any differences in the 'good' and the 'bad'
>>> files (also read-only or not). Also, try to change the last parameter to true
>>> instead of false, as this parameter will validate the 'ImageData'.
>>>
>>> Hope this helps you,
>>>
>>> Michel van den Berg
>>>
>>> "Lance" <nu***@business.com> schreef in bericht
>>> news:ei*************@TK2MSFTNGP10.phx.gbl...
>>>> hey all,
>>>>
>>>> first time vb.net 2005 user, after sticking vb6 out for a long time...
>>>>
>>>> anyway, using this code
>>>> ======================
>>>> Dim FS As FileStream = File.OpenRead(Filename)
>>>> Dim theImage As Image
>>>> Try
>>>> theImage = Image.FromStream(FS, False, False)
>>>> Catch ex As Exception
>>>> Debug.Print(FS.Name)
>>>> FS.Close()
>>>> Exit Sub
>>>> End Try
>>>>
>>>> Dim Width As Integer = theImage.Width
>>>> Dim Height As Integer = theImage.Height
>>>> theImage.Dispose()
>>>> FS.Close()
>>>> ========================
>>>>
>>>> works fine except for on a handful of images. all of the images are tif files
>>>> that open in evey application i have ever tried to open them in. i'm just getting
>>>> the width and height without loading the entire image into memory (they are about
>>>> 150 MB each and there are thousands of them). the debug window shows:
>>>>
>>>> "A first chance exception of type 'System.ArgumentException' occurred in
>>>> System.Drawing.dll"
>>>>
>>>> on the "bad" ones and if i step into, the error i get is "Parameter not valid" at
>>>> the
>>>>
>>>> theImage = Image.FromStream(FS, False, False)
>>>>
>>>> line. what could be causing this? the code works for 99.9% of the images, but
>>>> not for a handful that are otherwise perfectly fine.
>>>>
>>>> thanks,
>>>> lance
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Nov 23 '05 #11

P: n/a
Dear Lance,

I must admit I am not sure why some work and some not. Perhaps, your
software uses different compression schemes to optimize?
In your case, I would probally go for a 3rd party toolkit like leadtools.
You could always create your own imaging library ;)

Michel van den Berg

"Lance" <nu***@business.com> schreef in bericht
news:ub**************@TK2MSFTNGP09.phx.gbl...
michel,

interestingly, there are some packbit compressed tif files that seem to
work.

lance

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Dear Lance,

As I suspected is your problem the picture itself. To be more precise:
within its compression it is using.
The working picture has no compression whereas the bad picture has. GDI+
does not support (that) compression with TIF files.
To verify my statement: I resaved the bad image without compression and
it now works.
So, I suggest, if possible, to alter the program generating these images
to output without compression.

Hope it helps,

Michel van den Berg

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in
bericht news:OB*************@TK2MSFTNGP10.phx.gbl...
sent...

"Michel van den Berg" <mv*@promontis.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dear Lance,

Could you perhaps send me some good and bad images, so that I may try
the code for myself? You can send it to my e-mail address.

Michel van den Berg
--
== Remove nospam to email me ==

"Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> schreef in
bericht news:O0**************@TK2MSFTNGP12.phx.gbl...
> michel,
>
> that's pretty much the code, yeah. i don't alter the stream - if by
> "alter" you mean change the image in any way. i'm just opening it
> long enough to be able to get the width and height of a tif file.
> please let me know if i missunderstood your question.
>
> by the way, the reason the third parameter is set to false is so that
> this can be done very quickly, as the are thousands of images to
> extract the dimensions from. as i mentioned, though, it doesn't
> matter whether the parameter is set to true, as it still produces the
> same error on the same images.
>
> lance
>
> "Michel van den Berg" <mv*@promontis.nl> wrote in message
> news:eB**************@TK2MSFTNGP11.phx.gbl...
>> Dear Lance,
>>
>> Is the code your posted the (real) code as implemented in your app,
>> or do you, for instance, alter or dispose the filestream?
>>
>> Michel van den Berg
>> --
>> == Remove nospam to email me ==
>>
>> "Lance" <nu***@business.com> schreef in bericht
>> news:OC****************@TK2MSFTNGP09.phx.gbl...
>>>i should have mentioned that i had already tried setting the third
>>>parameter to true. the same thing happens, unfortunately. none of
>>>the file are read only, or opened already. they were all actually
>>>created by the same software using the same parameters.
>>>
>>> the handful that return these errors open fine in every other tag
>>> viewer and image application. that's what is so frustrating.
>>>
>>> lance
>>>
>>>
>>>
>>> "Michel van den Berg" <mv*@promontis.nl> wrote in message
>>> news:e2**************@TK2MSFTNGP14.phx.gbl...
>>>> Dear Lance,
>>>>
>>>> I don't know if it will help you with answering your question, but
>>>> Image.FromStream() throws an ArgumentException when the stream does
>>>> not have a valid image format (see the docs for this). Perhaps this
>>>> is the case. If I were you, I would try to see if there are any
>>>> differences in the 'good' and the 'bad' files (also read-only or
>>>> not). Also, try to change the last parameter to true instead of
>>>> false, as this parameter will validate the 'ImageData'.
>>>>
>>>> Hope this helps you,
>>>>
>>>> Michel van den Berg
>>>>
>>>> "Lance" <nu***@business.com> schreef in bericht
>>>> news:ei*************@TK2MSFTNGP10.phx.gbl...
>>>>> hey all,
>>>>>
>>>>> first time vb.net 2005 user, after sticking vb6 out for a long
>>>>> time...
>>>>>
>>>>> anyway, using this code
>>>>> ======================
>>>>> Dim FS As FileStream = File.OpenRead(Filename)
>>>>> Dim theImage As Image
>>>>> Try
>>>>> theImage = Image.FromStream(FS, False, False)
>>>>> Catch ex As Exception
>>>>> Debug.Print(FS.Name)
>>>>> FS.Close()
>>>>> Exit Sub
>>>>> End Try
>>>>>
>>>>> Dim Width As Integer = theImage.Width
>>>>> Dim Height As Integer = theImage.Height
>>>>> theImage.Dispose()
>>>>> FS.Close()
>>>>> ========================
>>>>>
>>>>> works fine except for on a handful of images. all of the images
>>>>> are tif files that open in evey application i have ever tried to
>>>>> open them in. i'm just getting the width and height without
>>>>> loading the entire image into memory (they are about 150 MB each
>>>>> and there are thousands of them). the debug window shows:
>>>>>
>>>>> "A first chance exception of type 'System.ArgumentException'
>>>>> occurred in System.Drawing.dll"
>>>>>
>>>>> on the "bad" ones and if i step into, the error i get is
>>>>> "Parameter not valid" at the
>>>>>
>>>>> theImage = Image.FromStream(FS, False, False)
>>>>>
>>>>> line. what could be causing this? the code works for 99.9% of
>>>>> the images, but not for a handful that are otherwise perfectly
>>>>> fine.
>>>>>
>>>>> thanks,
>>>>> lance
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Nov 23 '05 #12

P: 1
Hi Michael,

I have the same exact problem. Have you figured out the reason for such error?

I am hoping to just able to detect whether the stream that I am about to pass into System.Drawing.Image.FromStream has a valid image format or not. If it is, then I'll pass it in, if not I won't call FromStream, so I can avoid having it throw an exception.

Is there anyway this can be done? Is there a byte in the stream that tells me whether it has a valid image format? Or maybe the length of the stream? I know all cases aren't null and have certain length, could the "bad" image be determined by certain characteristics?

Thanks!

Janh
Apr 19 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.