关于图片显示的问题,在线等.......

cbzdream 2004-08-14 07:24:55
在vb中,我想通过picturebox控件或image控件浏览某文件夹下的所有jpg图片,通过两个按钮(“上一副图片”,“下一副图片”)来浏览,有两个问题:
1,怎么实现浏览图片的功能?
2,我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?使用滚动条可以吗?怎么使用滚动条来实现??谢谢!!!
...全文
186 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2004-08-14
  • 打赏
  • 举报
回复
'add an image,two commandbutton to form1:

Dim alljpgfile() As String, index As Integer

Sub getallfile(ByVal mydir As String, ByRef x() As String)
Dim fname As String, i As Integer
If Right(mydir, 1) <> "\" Then mydir = mydir & "\"
fname = Dir(mydir & "\*.jpg")
i = 1
Do While fname <> ""
ReDim Preserve x(1 To i)
x(i) = mydir & fname
i = i + 1
fname = Dir
Loop
End Sub

Private Sub Command1_Click()
If index = UBound(alljpgfile) Then
index = 1
Else
index = index + 1
End If
Image1.Picture = LoadPicture(alljpgfile(index))
End Sub

Private Sub Command2_Click()
If index = 1 Then
index = UBound(alljpgfile)
Else
index = index - 1
End If
Image1.Picture = LoadPicture(alljpgfile(index))
End Sub

Private Sub Form_Load()
Command1.Caption = "prev"
Command2.Caption = "next"
index = 1
Image1.Stretch = True
getallfile "C:\Documents and Settings\hsy\My Documents\My Pictures", alljpgfile
Image1.Picture = LoadPicture(alljpgfile(index))
End Sub
helanshan 2004-08-14
  • 打赏
  • 举报
回复
1,怎么实现浏览图片的功能?
用楼上的方法,或使用pciturebox控件数组。
2,我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?
使用:PaintPicture方法。对较大图片可以缩小,或只显示局部。
Picture1.PaintPicture Picture,x1,y1,[width1],[height1],[x2],[y2],[width2],[height2],[opcode]
说明:参数Picture为要绘制的图象或加载的图片
x1,y1为图象或图片在控件上的位置,,[width1],[height1为图象或图片在控件上的高度或宽度。[width1],[height1 如果取负值,可以把图象或图片翻转显示。
[x2],[y2]],[width2],[height2]四个参数可以指定只绘制图象或图片的局部。
[opcode]参数指定绘制的方法,建议省略。

kxyzjm 2004-08-14
  • 打赏
  • 举报
回复
Dim idx As Integer
Private Sub Command1_Click()
If idx >= 1 Then
idx = idx - 1
Image1.Picture = LoadPicture(File1.Path & "\" & File1.List(idx))

End If
End Sub

Private Sub Command2_Click()
If idx < File1.ListCount - 2 Then
idx = idx + 1
Image1.Picture = LoadPicture(File1.Path & "\" & File1.List(idx))
End If
End Sub

Private Sub Dir1_Change()

File1.Path = Dir1.Path
File1.Refresh
On Error GoTo chli:
idx = 0
Image1.Picture = LoadPicture(File1.Path & "\" & File1.List(idx))
chli:
Exit Sub
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
Dir1.Refresh
End Sub
BlueBeer 2004-08-14
  • 打赏
  • 举报
回复
'一个简单的滚动条例子
'Form1中放一个PictureBox: Picture1
'Picture1中放一个Image: Image1
'一个HScrollBar: HScroll1
'一个VScrollBar: VScroll1

Private Sub Form_Load()
With Image1
.Move 0, 0
.Picture = LoadPicture("c:\windows\logow.sys")
'如果这句出错,请改为其他的图片文件
Picture1.Move 0, 0, .Width \ 2, .Height \ 2
End With
With Picture1
HScroll1.Move 0, .ScaleHeight - 255, .ScaleWidth - 255, 255
HScroll1.Max = .ScaleWidth + 255 + 255 \ 2
HScroll1.LargeChange = .ScaleWidth / 50
HScroll1.SmallChange = .ScaleWidth / 50
VScroll1.Move .ScaleWidth - 255, 0, 255, .ScaleHeight - 255
VScroll1.Max = .ScaleHeight + 255 + 255 \ 2
VScroll1.LargeChange = .ScaleHeight / 50
VScroll1.SmallChange = .ScaleHeight / 50
Dim cmdMask As CommandButton
Set cmdMask = Controls.Add("vb.commandbutton", "mask", Picture1)
cmdMask.Move .ScaleWidth - 255, .ScaleHeight - 255, 255, 255
cmdMask.Enabled = False
cmdMask.Visible = True
End With
End Sub

Private Sub HScroll1_Change()
Image1.Left = -HScroll1.Value
End Sub

Private Sub VScroll1_Change()
Image1.Top = -VScroll1.Value
End Sub
online 2004-08-14
  • 打赏
  • 举报
回复
//我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?使用滚动条可以吗?怎么使用滚动条来实现??谢谢!!!

你试试image控件,设置stretch为true,可以以一定的大小显示
zhujiechang 2004-08-14
  • 打赏
  • 举报
回复
或者本文件夹下的文件可以通过dir函数或者filebox控件取得.
直接使用image控件作为加载图片的控件,loadpicture函数.
pciturebox作为容器,实现image控件在picturebox容器内的移动.那么就用滚动条实现.
rainstormmaster 2004-08-14
  • 打赏
  • 举报
回复
//怎么实现浏览图片的功能

set picture1.picture=loadpicture("c:\test.jpg")
image控件类似

//我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?使用滚动条可以吗?怎么使用滚动条来实现??谢谢!!!

可以,参考:http://community.csdn.net/Expert/topic/3263/3263473.xml?temp=.2826044

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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