在图片框1中创建错误图片

时间:2012-04-03 03:10:00

标签: vb.net

我的系统中有这个代码,用于通过格式化的blob从数据库中检索图像。但有些数据库记录没有图片([BLOB - 0 B])。如果图片不可用,请列出我在图片框1中放置错误图片的代码。

Dim bytes() as byte
bytes = (objdr("picture"))

Dim memStream as New MemoryStream(bytes)
PictureBox1.image = Drawing.Image.FromStream(memStream)

我正在使用Microsoft Visual Basic 2008

1 个答案:

答案 0 :(得分:0)

我将尝试使用此代码: DirectCast似乎是从数据库中读取Blob字段的正确方法 然后检查您是否有要显示的内容或尝试从您的资源中获取图像

 ' Get the image from the database.
 bytes = DirectCast(objdr("picture"), Byte()) 
 If (Not bytes Is Nothing) Then
     Dim memStream as New MemoryStream(bytes)  
     PictureBox1.image = Drawing.Image.FromStream(memStream)       
 Else
     PictureBox1.image = My.Resources.<Name_of_res_file>.<Name_of_image_resource>
 End If