重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
将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)
#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
如果TextBox1.Text包括了路径文件名;
PictureBox1.Image.Save(TextBox1.Text)
我理解你
我写过图片网络传输的和你要求的一样
为了不把图片写到硬盘 又从硬盘读取
而直接保存图片内存流 进行网络传输
从网络读取的图片byte数组转成图片代码如下
Dim mStream As New IO.MemoryStream
mStream.Write(b, 0, b.length) '这里b就是你的一维数组了
Dim Img As New Bitmap(mStream)
mStream.Close()
mStream.Dispose()
下面是把图片保存到一维数组的方法
Dim Stream As New IO.MemoryStream
im.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg)
im = Nothing
Stream.Flush()
Dim b As Byte() = Stream.ToArray
Stream.Dispose()
now()可以返回当前时间,如果你要把它作文件名,那么需要先转换成string,可以使用
format函数
,比如format(now(),