【发布时间】:2017-12-22 03:54:58
【问题描述】:
我正在从数据库中读取图像。 我读取了一个字段的二进制/blob,并将其转换为如下图像:
Public Function BytesToImage(ByVal ByteArr() As Byte) As Image
If ByteArr.Length < 1 Then
Return Nothing
End If
Dim ImageStream As MemoryStream 'Needs to stay open for the image's life-time
Dim nImage As Image = Nothing
Try
ImageStream = New MemoryStream(ByteArr)
nImage = Image.FromStream(ImageStream, True)
Catch ex As Exception
nImage = Nothing
End Try
Return nImage
End Function
我不能使用“使用 nImageStream 作为新的 MemoryStream(ByteArr)”,因为图像在一段时间后会“死”。 根据文档,MemoryStream 需要在图像的生命周期内保持打开状态。
现在我想知道什么是最好的。 我应该不关心 MemoryStream 而只是接受它在那里并且仍然“在后台”打开,还是应该克隆图像并关闭内存流?
【问题讨论】:
标签: vb.net image bitmap memorystream