将图像存储在SQL Server数据库中

编程入门 行业动态 更新时间:2024-10-25 08:18:50
本文介绍了将图像存储在SQL Server数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用vb和wcf Servics将图像存储在数据库varbinary列中 使用代码

I Am trying to store image in database varbinary Column using vb and wcf Servics Using code

Private Function SaveImage() As Byte() Dim arrayImage() As Byte = Nothing If (pic_meetPicture.Image Is Nothing) Then arrayImage = Nothing Else Try Dim ms As New MemoryStream Me.pic_meetPicture.Image.Save(ms, Me.pic_meetPicture.Image.RawFormat) arrayImage = ms.GetBuffer ms.Close() arrayImage = Process.Compressor.UICompressor.Compress(arrayImage) Catch ex As Exception End Try End If Return arrayImage End Function Public Shared Function Compress(ByVal buffer As Byte()) As Byte() Dim ms As MemoryStream = New MemoryStream() Dim zip As GZipStream = New GZipStream(ms, CompressionMode.Compress, True) zip.Write(buffer, 0, buffer.Length) zip.Close() ms.Position = 0 Dim outStream As MemoryStream = New MemoryStream() Dim compressed() As Byte = New Byte(ms.Length) {} ms.Read(compressed, 0, compressed.Length) Dim gzBuffer() As Byte = New Byte(compressed.Length + 4) {} System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length) System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4) Return gzBuffer End Function

用于显示图像

for display image

Private Sub SetImage(ByVal array As ArrayList) Dim arrayImage() As Byte = array(0).Image arrayImage = CType(Process.Compressor.UICompressor.Decompress(arrayImage), Byte()) If arrayImage IsNot Nothing Then Dim ms As New MemoryStream(arrayImage) pic_meetPicture.Image = Image.FromStream(ms) pic_meetPicture.SizeMode = PictureBoxSizeMode.StretchImage End If End Sub

Public Shared Function Decompress(ByVal gzBuffer As Byte()) As Byte() Dim ms As MemoryStream = New MemoryStream() Dim msgLength As Integer = BitConverter.ToInt32(gzBuffer, 0) ms.Write(gzBuffer, 4, gzBuffer.Length - 4) Dim buffer() As Byte = New Byte(msgLength) {} ms.Position = 0 Dim zip As GZipStream = New GZipStream(ms, CompressionMode.Decompress) zip.Read(buffer, 0, buffer.Length) Return buffer End Function

但是当从数据库中获取图像时出现错误有效参数" 请帮助 感谢

But when fetch image from databse then getting error ''parameter in valid'' please Help thanks

推荐答案

无需查看将数据存储在DB中的代码,我就可以确定问题出在哪里:停止将字符串连接起来以形成ans SQL命令! 请参阅此处:为什么我会得到一个参数无效."从数据库读取图像时出现异常? [ ^ ] Without looking at your code to store the data in teh DB, I can be pretty sure what the problem is: Stop concatenating strings to form ans SQL command! See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]

更多推荐

将图像存储在SQL Server数据库中

本文发布于:2023-10-28 19:10:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537526.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   图像   SQL   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!