image.fromstream错误 [英] image.fromstream error

查看:45
本文介绍了image.fromstream错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,


第一次使用vb.net 2005用户,在长时间坚持使用vb6之后......


无论如何,使用此代码

======================

Dim FS As FileStream = File.OpenRead (文件名)

将图像变暗为图像

尝试

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

Catch ex As Exception

Debug.Print(FS.Name)

FS.Close()

退出Sub

结束尝试


Dim Width As Integer = theImage.Width

Dim Height As Integer = theImage.Height

theImage .Dispose()

FS.Close()

======================== br />

工作正常,除了一些图像。所有的图像都是tif文件打开

在evey应用程序中我试过打开它们。我只是得到宽度和

高度而不加载将整个图像存储到内存中(每个大约150 MB)

是数千个。调试窗口显示:


"'
System.Drawing.dll"

在坏上如果我介入,我得到的错误是参数无效。在


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


行。可能是什么导致了这个?该代码适用于99.9%的图像,但不适用于

少数,否则完全没问题。


谢谢,

lance

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

推荐答案

亲爱的Lance,


我不知道它是否能帮助你回答你的问题,但

Image.FromStream()在流没有

a有效图像格式时抛出ArgumentException(请参阅相关文档)。也许情况就是这样。如果我是你b $ b,我会试着看看好和坏文件中是否有任何差异(也读取 - 只是或不)。另外,尝试将最后的

参数更改为true而不是false,因为此参数将验证

''ImageData''。


希望这会对你有所帮助,


Michel van den Berg


" Lance" < NU *** @ business.com> schreef in bericht

news:ei ************* @ TK2MSFTNGP10.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...
嘿all,
第一次使用vb.net 2005用户,长时间坚持使用vb6后......无论如何,使用此代码
========= =============
Dim FS As FileStream = File.OpenRead(文件名)
将图像变暗为图像
尝试
theImage = Image.FromStream (FS,False,False)
Catch ex As Exception
Debug.Print(FS.Name)
FS.Close()
退出Sub
结束尝试

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

除少数图像外,工作正常。所有的图像都是在evey应用程序中打开的文件,我试过打开它们。
我只是得到宽度和高度而不将整个图像加载到内存中(它们各自大约150 MB,并且有数千个)。
调试窗口显示:

类型''System.ArgumentException''发生的第一次机会异常
"

关于坏的错误如果我介入,我得到的错误是参数不是
有效。在

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

。可能是什么导致了这个?该代码适用于99.9%的
图像,但不适用于其他完全正常的少数。

感谢,
lance
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



我应该提到我已经尝试将第三个参数设置为true。不幸的是,

同样的事情发生了。这些文件都不是只读的,或者已经打开过了。

它们都是由相同的软件使用相同的参数实际创建的。


返回的少数文件这些错误在每个其他标签查看器和图像中都可以正常运行

应用程序。这真令人沮丧。


lance


" Michel van den Berg" < mv*@promontis.nl>在消息中写道

新闻:e2 ************** @ TK2MSFTNGP14.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...
亲爱的Lance,

我不知道它是否会帮助你回答你的问题,但是当流没有有效的图像格式时,Image.FromStream()
会抛出ArgumentException(参见
docs for this)。也许情况就是这样。如果我是你,我会试着看看好和坏文件中是否存在任何差异(也可以是只读的)。另外,尝试将最后一个参数更改为true而不是false,因为此参数将验证
''ImageData''。

希望这对您有所帮助,
Michel van den Berg

" Lance" < NU *** @ business.com> schreef in bericht
新闻:ei ************* @ TK2MSFTNGP10.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...
嘿all,
第一次使用vb.net 2005用户,长时间坚持使用vb6后......无论如何,使用此代码
============= =========
Dim FS As FileStream = File.OpenRead(Filename)
将图像变暗为图像
尝试
theImage = Image.FromStream(FS,False ,False)
Catch ex As Exception
Debug.Print(FS.Name)
FS.Close()
退出Sub
结束尝试

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

除少数图片外,效果很好。所有的图像都是在我试过打开它们的evey应用程序中打开的tif文件。我只是获得宽度
和高度而不将整个图像加载到内存中(它们是关于每个150 MB,并且有数千个)。调试窗口显示:

"类型''System.ArgumentException''的第一次机会异常发生在
System.Drawing.dll"

上"坏的QUOT;如果我介入,我得到的错误是参数无效。在

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

。可能是什么导致了这个?该代码适用于99.9%的图像,但不适用于少数几个完全正常的图像。

感谢,
lance
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




亲爱的Lance,


您发布的代码是您实现的(真实)代码吗?应用程序,或者做什么?b $ b你改变或处置文件流?


Michel van den Berg

-

==删除nospam给我发电子邮件==


" Lance" < NU *** @ business.com> schreef in bericht

新闻:OC **************** @ TK2MSFTNGP09.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...
我应该有提到我已经尝试将第三个
参数设置为true。不幸的是,同样的事情发生了。没有任何
文件是只读的,或已经打开过。它们实际上都是由使用相同参数的相同软件创建的。

返回这些错误的少数几个在其他标签查看器和图像应用程序中打开正常。这就是令人沮丧的事情。



Michel van den Berg < mv*@promontis.nl>在消息中写道
新闻:e2 ************** @ TK2MSFTNGP14.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...
亲爱的Lance,
案例。如果我是你,我会试着看看好和坏文件是否有任何差异(也可以是只读)。另外,尝试将最后一个参数更改为true而不是false,因为此参数
将验证''ImageData''。

希望这对您有所帮助,
Michel van den Berg

" Lance" < NU *** @ business.com> schreef in bericht
新闻:ei ************* @ TK2MSFTNGP10.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...
嘿all,
第一次使用vb.net 2005用户,长时间坚持使用vb6后......无论如何,使用此代码
============= =========
Dim FS As FileStream = File.OpenRead(Filename)
将图像变暗为图像
尝试
theImage = Image.FromStream(FS,False ,False)
Catch ex As Exception
Debug.Print(FS.Name)
FS.Close()
退出Sub
结束尝试

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

除少数图片外,效果很好。所有的图像都是在evey应用程序中打开的文件,我试过打开它们。
我只是得到宽度和高度而不将整个图像加载到内存中(它们各约150 MB,有数千个它们)。调试窗口显示:

System.Drawing.dll中发生了'System.ArgumentException'类型的第一次机会异常'

"坏的QUOT;如果我介入,我得到的错误是参数不是
有效。在

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

。可能是什么导致了这个?该代码适用于99.9%的
图像,但不适用于其他完全正常的少数。

感谢,
lance
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





这篇关于image.fromstream错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆