从数据库中提取图像&显示在图片框中 [英] Extracting Image from database & displaying in picture box

查看:72
本文介绍了从数据库中提取图像&显示在图片框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过ado.net和vb.net从数据库到图片框显示图像


我在图像下存储的sql server 2000表中有一些图像'' 数据类型。我想在vb.net表格中的图片框中提取并显示它们


我感谢你对此有任何帮助


谢谢

PS

解决方案

http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp


-


WG Ryan,eMVP

http ://forums.devbuzz.com/
http:/ /www.knowdotnet.com/williamryan.html
http:/ /www.msmvps.com/WilliamRyan/

" PS" <一个******* @ discussions.microsoft.com>在留言中写道

news:7B ********************************** @ microsof t.com ...

我想通过ado.net
和vb.net从数据库到图片框显示图像?
我在sql中有一些图像存储在''image''
数据类型下的server 2000表。我想在一个以
vb.net形式出现的图片框中提取和显示它们。
我感谢你们提供的任何帮助。

谢谢,
PS



你好PS,


从文件中读取它,将其写入文件,放入它在数据库中,

读取它到数据库,


使用的是一个XML文件,只是为了让它变得简单。


我希望这有点帮助。


Cor


私人abyt()As Byte

作为新的OpenFileDialog私有

私有sf作为新的SaveFileDialog

私有子Button1_Click(ByVal发送者作为System.Object,ByVal e As

System.EventArgs)处理Button1.Click

''读取图片并将其放入bytearray中

如果fo.ShowDialog = DialogResult.OK那么

Dim fs As New IO.FileStream(fo.FileName,_

IO.FileMode.Open)

Dim br As New IO.BinaryReader(fs)

abyt = br.ReadBytes(CInt(fs.Length))

br.Close()

''只显示没有文件读取错误的样本

Dim ms As New IO.MemoryStream(abyt)

Me.PictureBox1.Image = Image.FromStream(ms)

结束如果

结束Sub $ />

Private Sub Button2_Click(ByVal sender As System.Object,ByVal _
$ b $ as As System.EventArgs)处理Button2.Click

''从bytearray写一张图片

如果sf.ShowDialog = DialogResult.OK然后

Dim fs As New IO.FileStream(sf.FileName,_

IO.FileMode.CreateNew)

Dim bw As New IO.BinaryWriter(fs)

bw.Write(abyt)

b.Close()

结束如果

结束子


Private Sub Button3_Click(ByVal sender As System.Object,ByVal _
$ b $ as As System.EventArgs)处理Button3.Click

''将bytearray写入数据集

Dim ds作为新数据集

ds.Tables.Add(New DataTable(" Photo"))

ds.Tables(0).Columns.Add(New DataColumn(" Sample"))

ds.Tables(0).Columns(0).DataType =

System.Type.GetType(" System.Byte []")

ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)

ds.Tables(0).Rows(0)(0)= abyt

Dim sf As New SaveFileDialog

如果sf.ShowDialog = DialogResult.OK然后

ds.WriteXml(sf.FileName,XmlWriteMode.WriteSchema)

结束如果

结束子


Private Sub Button4_Click(ByVal sender As System.Object,_

ByVal e As System.EventArgs)处理Button4.Click

''正在读图片来自数据集

Dim ds作为新数据集

如果fo.ShowDialog = DialogResult.OK那么

ds.ReadXml(fo.FileName)

结束如果

abyt = CType(ds.Tables(0).Rows(0)(0),Byte())

Dim ms As New IO.MemoryStream(abyt)

Me.PictureBox1.Image = Image.FromStream(ms)

End Sub


<块引用>嗨比尔,


我不知道你与该样本的制造商的关系,但在我的

意见中使用了它更多的代码和资源(磁盘)比需要的更多。


我知道我必须完成我开始使用的网站,我开始用

然而我有疑问它具有真正的价值来完成它已经

已经这么多了。 Herfried确实对它有所了解,但是这不是有人要判断的,你能不能看看我这个吗?


(我还有你的发送电子邮件地址,给你链接)。


Cor


I want to display the image from database to picture box through ado.net and vb.net

I have some images present in a sql server 2000 table stored under ''image'' datatype. I want to extract and display them in a picture box present in a vb.net form

I appreciate any help on this

Thanks
PS

解决方案

http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
"PS" <an*******@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...

I want to display the image from database to picture box through ado.net and vb.net?
I have some images present in a sql server 2000 table stored under ''image'' datatype. I want to extract and display them in a picture box present in a
vb.net form.
I appreciate any help on this.

Thanks,
PS



Hi PS,

Reading it from a file, writing it to a file, putting it in the database,
reading it to the database,

Used is an XML file just to make it easy as sample.

I hope this helps a little bit.

Cor

Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
''Reading a picture and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
''just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
''writing a picture from a bytearray
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
''writing a bytearray to a dataset
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType =
System.Type.GetType("System.Byte[]")
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyt
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema)
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
''reading a picture from a dataset
Dim ds As New DataSet
If fo.ShowDialog = DialogResult.OK Then
ds.ReadXml(fo.FileName)
End If
abyt = CType(ds.Tables(0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub


Hi Bill,

I do not know your relation to the maker of that sample, however in my
opinion uses it very much more code and resources (disk) than is needed.

I know that I have to complete that website I started with, I started with
it however I am in doubt if it has real value to complete it there is
already so much. Herfried did look to it, however that is not someone to be
a judge, will you have a look for me to it?

(I have still your email adres, to send you the link).

Cor


这篇关于从数据库中提取图像&amp;显示在图片框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆