1,453
社区成员




'如何做才能通过图片的(长 与 宽)和(图片的像素)来显示图片呢?(就是打开时能像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
'增加一个按扭.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