重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb点虐 图片存储 vb picture 保存

vb点虐 中如何将图片保存到SQL数据库

#Region "二进制文件的存储函数" Public Function BinaryToFile(ByRef TableRowColItem As Object, ByVal FileName As String) As Boolean Dim data As Byte() = TableRowColItem

目前成都创新互联公司已为上千家的企业提供了网站建设、域名、网页空间、网站托管维护、企业网站设计、徐水网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

Dim myfilestream As New System.IO.FileStream(FileName, IO.FileMode.Create)

myfilestream.Write(data, 0, data.Length)

myfilestream.Close()

Return True

End Function Public Function BinaryToImage(ByRef TableRowColItem As Object, ByRef image As Image) As Boolean Dim data As Byte() = TableRowColItem Dim imgStream As New System.IO.MemoryStream '(data)

imgStream.Write(data, 0, data.Length)

image = System.Drawing.Image.FromStream(imgStream)

imgStream.Close()

imgStream.Dispose() Return True

End Function

Public Function BinaryFromFile(ByVal FileName As String, ByRef TableRowColItem As Object) As Boolean Using myfilestream As New FileStream(FileName, FileMode.Open, FileAccess.Read)

Dim data() As Byte

ReDim data(myfilestream.Length - 1)

myfilestream.Read(data, 0, myfilestream.Length)

myfilestream.Close()

TableRowColItem = data End Using

Return True

End Function Public Function BinaryFromImage(ByRef Image As Image, ByRef TableRowColItem As Object) As Boolean

Dim imgStream As New MemoryStream

Dim b As New Bitmap(Image) b.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg) Dim data As Byte() = imgStream.GetBuffer

TableRowColItem = data

data = TableRowColItem

imgStream.Close()

imgStream.Dispose() Return True

End Function Public Function BinaryFromImage(ByVal Image As Image, ByRef TableRowColItem As Object, ByVal imgFormat As System.Drawing.Imaging.ImageFormat) As Boolean

Dim imgStream As New MemoryStream

'Image.Save(imgStream, imgFormat)

'Dim b As New Bitmap(Image)

'b.Save("c:\a.bmp", imgFormat)

'b.Save("c:\a.bmp", imgFormat) Dim data As Byte() = imgStream.GetBuffer TableRowColItem = data

data = TableRowColItem

imgStream.Close()

Return True

End Function

#End Region

怎么让VB.NET 上传图片到SQL 数据库只保存路径,图片保存到文件

一个参考过程,你试试 这里写下一个过程为: insert into pub_infor values('1234',0x,'this is a sample') 然后读入图片: sp_textcopy @srvname = '.', @login = 'sa', @password = 'sa', @dbname = 'pubs', @tbname = 'pub_info', @colname = 'logo', @filename = 'c:\picture.bmp', @whereclause = " WHERE pub_id='1234' ", @direction = 'I' 读出为: sp_textcopy @srvname = '.', @login = 'sa', @password = 'sa', @dbname = 'pubs', @tbname = 'pub_info', @colname = 'logo', @filename = 'D:\picture.bmp', @whereclause = " WHERE pub_id='1234' ", @direction = 'O' 清空:update 表 set 列=null 最后注意事项:因为filename的字符长度只有30个:即: @filename varchar (30), 所以实际应用的时候最好改为255个,当含有比较长的路径的时候就会报错: ERROR: Augment 'xxx' unrecognize 还有参数的长度@exec_str varchar (255)也修改下比较好: 我改成了这样子: CREATE PROCEDURE sp_textcopy ( @srvname varchar (30), @login varchar (30), @password varchar (30), @dbname varchar (30), @tbname varchar (30), @colname varchar (30), @filename varchar (255), @whereclause varchar (40), @direction char(1)) AS DECLARE @exec_str varchar (400) SELECT @exec_str = 'textcopy /S ' + @srvname + ' /U ' + @login + ' /P ' + @password + ' /D ' + @dbname + ' /T ' + @tbname + ' /C ' + @colname + ' /W "' + @whereclause + '" /F ' + @filename + ' /' + @direction EXEC master..xp_cmdshell @exec_str 就只这样子了,感觉上T_SQL编程还是挺强大的,有时间应该好好学习下。 回答: 这里以SQL_server2000中的pubs数据库中的pub_info表为例来说说其中的过程:pub_info表包含:pub_id,logo,pr_info,其中logo属于image超长字段,应用存储过程奖图像存储在数据库的步骤包括: 1:首先:是插入一个列: 比如:insert into pub_infor values('1234',0x,'this is a sample')其中0x只是为了确保image字段不能为空:因为下面的存储过程:textcopy 用textcopy把图片或者文件拷贝到image类型字段之前,image类型的字段不能为空。先插入0x(或者0x0)到这个字段,然后就可以用textcopy了。 否则就会报这样的错误: ERROR: Text or image pointer and timestamp retrieval failed. 2:接下来建立存储过程: CREATE PROCEDURE sp_textcopy ( @srvname varchar (30), @login varchar (30), @password varchar (30), @dbname varchar (30), @tbname varchar (30), @colname varchar (30), @filename varchar (30), @whereclause varchar (40), @direction char(1)) AS DECLARE @exec_str varchar (255) SELECT @exec_str = 'textcopy /S ' + @srvname + ' /U ' + @login + ' /P ' + @password + ' /D ' + @dbname + ' /T ' + @tbname + ' /C ' + @colname + ' /W "' + @whereclause + '" /F ' + @filename + ' /' + @direction EXEC master..xp_cmdshell @exec_str 说明: 其中xp_cmdshell: 以操作系统命令行解释器的方式执行给定的命令字符串,并以文本行方式返回任何输出。授予非管理用户执行 xp_cmdshell 的权限。我自己的理解是: textcopy就像是一个dos命令:就是说实际的文件copy命令是类似操作系统执行的。

采纳哦

vb点虐 怎样保存图片文件,并且保存的图片名称为当前时间

将PictureBox控件里的图片,保存为文件:

1,文件格式不变化:

PictureBox1.Image.Save("C:\" Format(Now, "HH-mm-ss") ".bmp")

2,文件格式有变化:

PictureBox1.Image.Save("C:\" Format(Now, "HH-mm-ss") ".bmp", System.Drawing.Imaging.ImageFormat.Bmp)


网站题目:vb点虐 图片存储 vb picture 保存
当前路径:http://cqcxhl.com/article/ddecdpp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP