现在一切都解决了。此GDI+一般错误由图片框本身引起。实际上,当我用数据库中的图像绑定记录并更新该记录而不更新PictureBox中的图像时,图像字段已使用框中的旧byte()数据设置,这导致了错误。
为了解决这个问题,我声明了一个byte()类型的变量来存储数据库中的temp image byte()数据,更新时,如果图像没有更改,则将使用该变量中的数据进行设置。
这是我解决所有问题的代码:
Try
If Miscellaneous.GetImageName(ofdPhoto).ToLower = "No_Photo.jpg".ToLower Then
.Image = Nothing
Else
If isImageChanged = True Then
Dim stream As New MemoryStream
pbImage.Image.Save(stream, pbImage.Image.RawFormat)
.Image = stream.GetBuffer()
isImageChanged = False
ElseIf isRemoveImage = True Then
.Image = Nothing
isRemoveImage = False
Else
.Image = tempImage
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try