请教下在image控件中显示图片的问题

IDtoID 2008-09-03 11:24:17

'如何做才能通过图片的(长 与 宽)和(图片的像素)来显示图片呢?(就是打开时能像windows的图片和传真查看器一样,

'根据图片的(长 与 宽)和(图片的像素)来显示图片).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Form_Resize()'这样做在显示时只是作了适应大小的调整.....
Picture1.Top = 100
Picture1.Left = 100
Picture1.Width = Me.ScaleWidth - Picture1.Left - 100
Picture1.Height = Me.ScaleHeight - Picture1.Top - 100
End Sub

Private Sub Picture1_Resize()
Image1.Top = 0
Image1.Left = 0
Image1.Width = Picture1.Width
Image1.Height = Picture1.Height
Image1.Stretch = True
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

'以下代码是来自下载的源码. 但看不懂是什么意思. (请教各位,如果要实现这样的效果该如何该呢?谢谢各位!)
Public Sub LoadPreview(FileName As String)
Dim ximg As cIMAGE
Dim PicRatio, xRatio As Single

Set ximg = New cIMAGE

With PicPreview
PicRatio = .Width / .Height
ximg.Load FileName
xRatio = ximg.ImageWidth / ximg.ImageHeight
If ximg.ImageHeight < ximg.ImageWidth Then
ximg.ReSize .Width * 15 / 16, 0, False
Else
ximg.ReSize 0, .Height * 15 / 16, False
End If
ImgPreview.Visible = False
ImgPreview.Left = (.ScaleWidth - ximg.ImageWidth) / 2
ImgPreview.Top = (.ScaleHeight - ximg.ImageHeight) / 2
ImgPreview.Width = ximg.ImageWidth
ImgPreview.Height = ximg.ImageHeight
ImgPreview.Picture = ximg.Picture
ImgPreview.Visible = True
.Tag = FileName
End With
Set ximg = Nothing

Exit Sub
Resume Next
End Sub

...全文
298 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
IDtoID 2008-09-03
  • 打赏
  • 举报
回复
可以了,太谢谢vflove兄..!
fvflove 2008-09-03
  • 打赏
  • 举报
回复
你将 bakPic 的自动改变大小设为True 你看一下.是不是OK的.
IDtoID 2008-09-03
  • 打赏
  • 举报
回复
谢谢fvflove兄..

如何才能实现根据图片的"尺寸和像素"来显示呢...

以上方法如果打开一张高度为800 宽度为600 的图片,那显示出来的效果是"以适应调整大小".
fvflove 2008-09-03
  • 打赏
  • 举报
回复

'增加一个按扭.Command1
'一个CommonDialog1
'一个Picture ; Name = bakPic Visible=False
'一个Picture ; Name = Picture1 ,在此图面框中再增加一个 Image1



Option Explicit

Private Sub Command1_Click()
CommonDialog1.ShowOpen
bakPic.Picture = LoadPicture(CommonDialog1.FileName)

Dim wScale As Double
Dim hScale As Double

wScale = Picture1.Width / bakPic.Width
hScale = Picture1.Height / bakPic.Height


If wScale > hScale Then
Image1.Width = bakPic.Width * hScale
Image1.Height = bakPic.Height * hScale
Else
Image1.Width = bakPic.Width * wScale
Image1.Height = bakPic.Height * wScale
End If


Image1.Left = (Picture1.Width - Image1.Width) / 2
Image1.Top = (Picture1.Height - Image1.Height) / 2
Image1.Stretch = True

Set Image1.Picture = bakPic.Picture

End Sub


mokton 2008-09-03
  • 打赏
  • 举报
回复
cIMAGE是什么东西,有待详解。
其实就是设置它的位置和大小。

1,453

社区成员

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

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