请问VB.net中如何保存BMP/jpg图像
2个回答
展开全部
我理解你
我写过图片网络传输的和你要求的一样
为了不把图片写到硬盘 又从硬盘读取
而直接保存图片内存流 进行网络传输
从网络读取的图片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()
我写过图片网络传输的和你要求的一样
为了不把图片写到硬盘 又从硬盘读取
而直接保存图片内存流 进行网络传输
从网络读取的图片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()
展开全部
你的要求很奇怪
要么把DB的字段里的2进制值输出成图象,
要么把图象通过流生成byte类型保存到DB
要么直接绘图输出
你的byte类型应该来自DB,Response.BinaryWrite(photo) 可以输出。
参考代码如下:
Dim db As New DBPsnUserBaseInfo(Me.ConnectString)
Dim photo As Object
photo = db.ShowPhoto(Request.QueryString("UserSID"))
Response.BinaryWrite(photo)
Public Function ShowPhoto(ByVal UserSID As Integer) As Object
Dim queryString As String = String.Empty
Dim objCmd As New SqlCommand()
Dim sdr As SqlDataReader = Nothing
ShowPhoto = Nothing
Try
queryString = "SELECT PHOTO FROM UserBasicInfoT WHERE USERSID =" & UserSID
objCmd.Connection = sqlConnection
objCmd.CommandText = queryString
sdr = objCmd.ExecuteReader
Dim imgdata As Byte
imgdata = New Byte
If sdr.Read Then
Return sdr(imgdata)
End If
sdr.Close()
Catch ex As Exception
Finally
End Try
End Function
要么把DB的字段里的2进制值输出成图象,
要么把图象通过流生成byte类型保存到DB
要么直接绘图输出
你的byte类型应该来自DB,Response.BinaryWrite(photo) 可以输出。
参考代码如下:
Dim db As New DBPsnUserBaseInfo(Me.ConnectString)
Dim photo As Object
photo = db.ShowPhoto(Request.QueryString("UserSID"))
Response.BinaryWrite(photo)
Public Function ShowPhoto(ByVal UserSID As Integer) As Object
Dim queryString As String = String.Empty
Dim objCmd As New SqlCommand()
Dim sdr As SqlDataReader = Nothing
ShowPhoto = Nothing
Try
queryString = "SELECT PHOTO FROM UserBasicInfoT WHERE USERSID =" & UserSID
objCmd.Connection = sqlConnection
objCmd.CommandText = queryString
sdr = objCmd.ExecuteReader
Dim imgdata As Byte
imgdata = New Byte
If sdr.Read Then
Return sdr(imgdata)
End If
sdr.Close()
Catch ex As Exception
Finally
End Try
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |