欢迎光临
我们一直在努力

sql server中image类型字段在vb.net中的读写操作_vb/vb.net教程

建站超值云服务器,限时71元/月

1.图片文件写入
            Dim tmpImg As image                    
            Dim r As DataRow                         
            Dim ms As New MemoryStream    
            Dim data() As Byte                         


            r = myDataSet.Tables(myTableName).NewRow
            tmpImg = Image.FromFile(“c:\xxx.jpg”)
            tmpImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
            tmpImg.Dispose()
            ReDim data(ms.Length)
            ms.Position = 0
            ms.Read(data, 0, System.Convert.ToInt32(ms.Length))


            …
            …          
            r(“pic”) = data
            myDataSet.Tables(myTableName).Rows.Add(r)
            …


2.图片数据的读出
            Dim tmpImg As image                    
            Dim r As DataRow                         
            Dim ms As New MemoryStream    
            Dim data() As Byte                         
            Dim r As Integer


            data=myDataSet.Tables(myTableName).Rows(r).Item(“pic”)
            ms = New MemoryStream
            ms.Write(data(0), 0, data(0).GetUpperBound(0))
           
            在窗体中显示
            Me.pic0.Image = Image.FromStream(msImg(0))
           
            存入到文件
            If  FileI.Exists(“c:\xxx.jpg”) Then
                  File.Delete(“c:\xxx.jpg”)
            End If
            fs = File.Create(“c:\xxx.jpg”)
            fs.Write(data, 0, data.GetUpperBound(0))
            fs.Close()

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » sql server中image类型字段在vb.net中的读写操作_vb/vb.net教程
分享到: 更多 (0)