BinaryReader关闭,但文件未释放 [英] BinaryReader closed but file not released

查看:95
本文介绍了BinaryReader关闭,但文件未释放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    Private Function GetImageSize(ByVal FileName As String) As Size
        Dim ImageSize As Size
        Using BR As New BinaryReader(New FileStream(FileName, FileMode.Open))
            Do
                If BR.ReadByte = &HFF Then If BR.ReadByte = &HC0 Then Exit Do
            Loop
            BR.ReadInt16() : BR.ReadByte()
            ImageSize.Height = BR.ReadByte
            ImageSize.Height = (ImageSize.Height << 8) + BR.ReadByte
            ImageSize.Width = BR.ReadByte
            ImageSize.Width = (ImageSize.Width << 8) + BR.ReadByte
        End Using
        Return ImageSize
    End Function

我想在鼠标滑过人们的名字时显示他们的照片.我希望能够调整图片框的大小以使其与各种照片成比例,并让Stretch属性处理其余的图片.

I want to display photos of people when the mouse passes over their name. I wanted to be able to size the picture box to be proportional to the various photographs and let the Stretch property handle the rest.

我使用约翰·魏恩(John Wein)提供的上述代码对2009年的问题进行了阅读

I used the code above offered by John Wein to a question from 2009 to read the dimension of the picture

效果很好,直到我两次超过同一个人为止.然后我得到一个错误,表明该文件正在被另一个进程使用.

It worked fine until I pass over the same person twice. Then I get an error that the file is in use by another process.

我尝试添加:

"BR.Close"

"BR.Close"

有无

"BR.Dispose"

"BR.Dispose"

但是文件在第二遍仍然被锁定.

But the file is still locked-out on the second pass.

当鼠标离开正方形时,我尝试设置"PictureBox.Image = Nothing",但该文件仍被视为正在使用并被锁定.

I tried setting "PictureBox.Image = Nothing" when the mouse leaves the square, still the file is seen as in use and locked.

 

对此有答案吗?

推荐答案

尝试一下:

Private Function GetImageSize(ByVal FileName As String) As Size        Dim ImageSize As Size        Using fs as New FileStream(FileName,FileMode.Open)           Using BR As New BinaryReader(fs)               Do                   If BR.ReadByte = &HFF Then If BR.ReadByte = &HC0 Then Exit Do               Loop               BR.ReadInt16() : BR.ReadByte()               ImageSize.Height = BR.ReadByte               ImageSize.Height = (ImageSize.Height << 8) + BR.ReadByte               ImageSize.Width = BR.ReadByte               ImageSize.Width = (ImageSize.Width << 8) + BR.ReadByte           End Using        End Using        Return ImageSize    End Function



这篇关于BinaryReader关闭,但文件未释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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