Path = "c:\\55.bmp";
FileStream buf = new FileStream(Path, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(buf);
byte[] cpimg = br.ReadBytes((int)buf.Length);
string sql = @"insert into tmp(cp_img)values(''" + cpimg + "' )";
数据库字段是image 类型,图片是300多k的bmp图片,存到数据库image字段后,
用查询分析器看image字段内容:0x53797374656D2E427974655B5D 只有几十个字节。
数据库image字段需要设置什么吗?
还是存储image字段不用byte[]类型?
http://blog.sina.com.cn/s/blog_49e8f18a0100b4jd.html
http://bliplink.blogspot.com/2008/11/c1.html
http://www.cnblogs.com/Tonyyang/archive/2007/06/02/768717.html
''' 从指定路径中读取一个图像文件并保存到字节数组中。
''' </summary>
''' <param name="imagename">指定的文件名</param>
''' <returns>从图像中读取出的数据。</returns>
''' <res>
''' 此方法供水晶报表显示图片使用,所返回字节数组是 BMP 或 JEPG 格式图像数据的数组。
'''
'''</res>
Shared Function ReadImage(ByVal path As String) As Byte()
Dim stream As IO.FileStream = Nothing
Try
stream = File.OpenRead(path)
Dim image As Image = image.FromStream(stream)
Dim myImage() As Byte = Nothing If image.RawFormat.Guid <> System.Drawing.Imaging.ImageFormat.Jpeg.Guid And image.RawFormat.Guid <> System.Drawing.Imaging.ImageFormat.Bmp.Guid Then
Dim memStream As System.IO.MemoryStream = New IO.MemoryStream()
image.Save(memStream, System.Drawing.Imaging.ImageFormat.Jpeg)
myImage = memStream.GetBuffer()
memStream.Close()
Else
stream.Position = 0
myImage = New Byte(stream.Length) {}
stream.Read(myImage, 0, CType(stream.Length, Integer))
End If
Return myImage
Catch ex As Exception Finally
If stream.ToString <> Nothing Then
stream.Close()
End If
End Try
End Function
我前面跟着做了一个图片上传的,图片也是数据库内保存(SQL Server)
而显示的时候,需要有那么几句byte转换的代码