求在图片框中显示图片的代码,在线等!!!

newsuperstar 2004-12-24 10:57:25
我想把数据库中的图片显示到PictureBox 中,请教各位高手原代码?
...全文
316 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
newsuperstar 2004-12-24
  • 打赏
  • 举报
回复
to: roger_xiong(卖女孩的小火柴~)

Dim mStmPic As ADODB.Stream ‘这一句上报错,类型未定义,ADODB.Stream 没用过,怎么用?
newsuperstar 2004-12-24
  • 打赏
  • 举报
回复
to: sky9705(帝国野猪) 你弄错了,从文件中显示我会做,现在是从数据库中取出显示。
roger_xiong 2004-12-24
  • 打赏
  • 举报
回复
用stream

'给相片框赋相片文件
Dim mStrPicPath As String
Dim mStmPic As ADODB.Stream
Dim mRsPic As ADODB.Recordset

'定义临时图片文件
mStrPicPath = App.Path & IIf(Right(App.Path, 1) = "\", "", "\") & "temp\temp.jpg"
'清除该文件,目的是为了防止以前的该文件没有删除
Kill mStrPicPath

Set mRsPic = New ADODB.Recordset
mRsPic.Open "select * from img where id='001'", gcnnData, 1, 3
If mRsPic.RecordCount > 0 Then
Set mStmPic = New ADODB.Stream
With mStmPic
.Mode = adModeReadWrite
.type = adTypeBinary
.Open
.Write mRsPic("photo")
.SaveToFile mStrPicPath
End With
End If

imgPro.Picture = LoadPicture(mStrPicPath)
sky9705 2004-12-24
  • 打赏
  • 举报
回复
不好意思,帖的这个例子算法有错误,
可是不能删自己的帖子。
sky9705 2004-12-24
  • 打赏
  • 举报
回复
Sub ShowPic(szFile As String, szpicture As PictureBox)
On Error Resume Next
Dim w As Integer, h As Integer
Dim goPic As picture
Dim Pict As picture

If IsFileExist(szFile) Then


Set goPic = LoadPicture(szFile)
If goPic.Width > goPic.Height Then
If goPic.Width > szpicture.ScaleWidth Then
w = szpicture.ScaleWidth
Else
w = goPic.Width '玂ㄓ
End If
h = w * goPic.Height \ goPic.Width
Else
If goPic.Height > szpicture.ScaleHeight Then
h = szpicture.ScaleHeight
Else
h = goPic.Height
End If
w = h * goPic.Width \ goPic.Height
End If
End If
szpicture.Cls
szpicture.PaintPicture goPic, 0, 0, w, h
szpicture.ToolTipText = szFile
Set goPic = Nothing
End Sub
sky9705 2004-12-24
  • 打赏
  • 举报
回复
从来都不用这样绑定来做,比如一个产品图片两张三张怎么办。。picture字段就一栏,
既然来了,就帮你顶一下。
newsuperstar 2004-12-24
  • 打赏
  • 举报
回复
我用ADODC做显示同样的错误,显示不能绑定到字段上,为什么?
newsuperstar 2004-12-24
  • 打赏
  • 举报
回复
谢谢: tztz520(午夜逛街)

做了还是不行,运行到下面的绑定语句上报错,向各位请教?
Set imgMain.DataSource = Rs
imgMain.DataField = Rs.Fields(7).Name ‘这一句显示不能绑定到字段,为什么?
tztz520 2004-12-24
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=195751
wangfub 2004-12-24
  • 打赏
  • 举报
回复
ADODB 2.5以上
用2.7吧就有了
newsuperstar 2004-12-24
  • 打赏
  • 举报
回复
不会吧,我在对象浏览器里(ADODB)下面从头找到尾都没有找到Stream
谁用过,给说一下。
roger_xiong 2004-12-24
  • 打赏
  • 举报
回复
是ADO了啦,你引用ADO对象就好了,microsoft activex data object 2.6 library

还有数据库中图片是以二进制存放的。

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧