我的表单上有4个图片框,用于存储图像并发送到我的数据库:我是通过表适配器完成的。图像通过以下函数转换为流:
Public Function ConvertImage(ByVal myImage As Image)As Byte()
'store image in memory before converting and 'create memory stream, save image in proper format Dim mStream As New MemoryStream myImage.Save(mStream, System.Drawing.Imaging.ImageFormat.Jpeg) 'convert new stream into bytes and indicate size Dim myBytes(mStream.Length - 1) As Byte mStream.Position = 0 mStream.Read(myBytes, 0, mStream.Length) Return myBytes
结束功能
我遇到的问题是当我的一个或多个图片框没有图像时,如果一个或多个图片框为空,我如何指示程序,然后将图像设置为Nothing。这是我的程序的缩短版本,因为它现在是
Private Sub btnSaveCategory_Click(sender As Object, e As EventArgs) Handles btnSaveCategory.Click
Dim picImage As Image = picBox1.Image
Dim picImage 2 As Image = picBox2.Image
Dim picImage 3 As Image = picBox3.Image
Dim picImage 4 As Image = picBox4.Image
PRODUCT_CATEGORYTableAdapter.InsertNewCategory(txtCategoryName.Text, ConvertImage(picImage),Image(picImage2), Image(picImage3), Image(picImage4))
End Sub
如何查看空白图片框并将其设置为空,这样我的程序就不会出错,因为一个或多个框上不存在图像?
谢谢。
答案 0 :(得分:0)
试试这个
If pictureBox.Image is Nothing Then
//do stuff here
End If