导致“参数异常”的原因是什么?将位图保存到流时?

发布于 2024-10-11 06:14:20 字数 1176 浏览 2 评论 0原文

谁能帮我解决下面的代码?我在第四行收到“参数异常”。内部异常什么都没有。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巡山小妖精 2024-10-18 06:14:20

尝试在没有此行的情况下运行代码:

StoringFilesHelper.SaveFile(fileName, stream, folderType) 

Try running your code without this line:

StoringFilesHelper.SaveFile(fileName, stream, folderType) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文