473,418 Members | 2,159 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,418 software developers and data experts.

image.fromstream error

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

Similar topics

3
by: CanyonJ | last post by:
I've been running into a frustrating problem for a while now. I use image.FromStream to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per...
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...
6
by: Saya | last post by:
Hello, This is a repost 'cause I haven't solve the problem: I can't use the System.Drawing class 'Image.FromStream' in the CompactFramework environment. What I've done with respect to Brendan's...
4
by: Detlef Huettenbach | last post by:
I was trying to convert a Windows Forms prototype application to an ASP.NET solution that makes use of loading data streams into the Image Web/Windows control. For WinForms no problem. However in...
6
by: hb | last post by:
Hi, Would you please give me some idea to convert/decode a Base 64 encoded GIF image string to a *.gif file in ASP.Net? Thank you hb
1
by: Mchuck | last post by:
I've seen several newsgroup topics everywhere concerning this, as well as a couple of articles from the MSDN website, but this error still baffles me. It has to do with using the...
9
by: Tom John | last post by:
Hi I am storing images in an access database, based on an MSDN article. The code i use to store is as follows: <code> 'Create the command object Dim command As New...
4
by: John Daly | last post by:
Does anyone know how to create an image (JPEG) from an HTTPResponse object? I am working on system that has a map pop up from our GIS department. I want create an image at runtime from this popup...
7
by: bookon | last post by:
I was running into the System.Drawing.Image.FromStream "parameter is not valid" on some of the images I was retrieving from a blob column in Sql Server. I thought there were corrupt images as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.