导致“参数异常”的原因是什么?将位图保存到流时?
谁能帮我解决下面的代码?我在第四行收到“参数异常”。内部异常什么都没有。
Using btm As Bitmap = Image.FromStream(importFile.InputStream)
Using newImage As Bitmap = ResizeImage(btm, StoringSize)
Dim stream As New MemoryStream
newImage.Save(stream, Imaging.ImageFormat.Bmp) 'Argument exception occurred. Parameter is not valid
StoringFilesHelper.SaveFile(fileName, stream, folderType)
End Using
End Using
这段代码运行正常,没有任何异常:
Using btm As Bitmap = Image.FromStream(importFile.InputStream)
Using newImage As Bitmap = ResizeImage(btm, StoringSize)
'Dim stream As New MemoryStream
'newImage.Save(stream, Imaging.ImageFormat.Jpeg)
'StoringFilesHelper.SaveFile(fileName, Stream, folderType)
Dim filePath As String = StoringFilesHelper.GetLocalPath(fileName, folderType)
newImage.Save(filePath)
End Using
End Using
终于,我明白了原因。 http://blog .lavablast.com/post/2007/11/29/The-Mysterious-Parameter-Is-Not-Valid-Exception.aspx 图像在 ResizeImage 方法中被处理。
Can anyone help me with the code below? I am getting an "Argument Exception" on 4th line. InnerException is Nothing.
Using btm As Bitmap = Image.FromStream(importFile.InputStream)
Using newImage As Bitmap = ResizeImage(btm, StoringSize)
Dim stream As New MemoryStream
newImage.Save(stream, Imaging.ImageFormat.Bmp) 'Argument exception occurred. Parameter is not valid
StoringFilesHelper.SaveFile(fileName, stream, folderType)
End Using
End Using
This code is working without any exceptions:
Using btm As Bitmap = Image.FromStream(importFile.InputStream)
Using newImage As Bitmap = ResizeImage(btm, StoringSize)
'Dim stream As New MemoryStream
'newImage.Save(stream, Imaging.ImageFormat.Jpeg)
'StoringFilesHelper.SaveFile(fileName, Stream, folderType)
Dim filePath As String = StoringFilesHelper.GetLocalPath(fileName, folderType)
newImage.Save(filePath)
End Using
End Using
Finally, I got the reason. http://blog.lavablast.com/post/2007/11/29/The-Mysterious-Parameter-Is-Not-Valid-Exception.aspx
Image was disposed in ResizeImage method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在没有此行的情况下运行代码:
Try running your code without this line: