VB里怎样在image或picture控件内按比例缩小显示图片
image控件srtetch属性会使图片变形,picture控件的AutoRedraw和AutoSize不能按控件大小缩小图片,用loadpicture函数可以显示固定尺...
image控件srtetch属性会使图片变形,picture控件的AutoRedraw和AutoSize不能按控件大小缩小图片,用loadpicture函数可以显示固定尺寸的图片吗?
展开
展开全部
可以用代码实现。
以下代码是我原来做过的实例里剪出来的,你可以参考一下,imgPreview 为Image对象。
Private Type PreviewSize
sngLeft As Single
sngTop As Single
sngWidth As Single
sngHeight As Single
intZoon As Integer
End Type
Private muPreviewSize As PreviewSize
Private Const cmChangeSize = 1.2
'// 缩小
Private Sub Command1_Click()
With muPreviewSize
.intZoon = .intZoon - 1
.sngHeight = .sngHeight / cmChangeSize
.sngWidth = .sngWidth / cmChangeSize
imgPreview.Stretch = True
imgPreview.Move .sngLeft, .sngTop, .sngWidth, .sngHeight
'// 如果已经缩小了9倍则缩小按钮不可用
If .intZoon < -9 Then
Command1.Enabled = False
Command2.Enabled = True
Else
Command2.Enabled = True
End If
End With
End Sub
'// 放大
Private Sub Command2_Click()
With muPreviewSize
.intZoon = .intZoon + 1
.sngHeight = .sngHeight * cmChangeSize
.sngWidth = .sngWidth * cmChangeSize
imgPreview.Stretch = True
imgPreview.Move .sngLeft, .sngTop, .sngWidth, .sngHeight
'// 如果已经放大了9倍则放大按钮不可用
If .intZoon > 9 Then
Command2.Enabled = False
Command1.Enabled = True
Else
Command1.Enabled = True
End If
End With
End Sub
Private Sub Form_Load()
With muPreviewSize
.intZoon = 0
'// + 0.5 为Image的边框
.sngHeight = imgPreview.Height + 0.5
.sngWidth = imgPreview.Width + 0.5
.sngLeft = imgPreview.Left
.sngTop = imgPreview.Top
End With
End Sub
以下代码是我原来做过的实例里剪出来的,你可以参考一下,imgPreview 为Image对象。
Private Type PreviewSize
sngLeft As Single
sngTop As Single
sngWidth As Single
sngHeight As Single
intZoon As Integer
End Type
Private muPreviewSize As PreviewSize
Private Const cmChangeSize = 1.2
'// 缩小
Private Sub Command1_Click()
With muPreviewSize
.intZoon = .intZoon - 1
.sngHeight = .sngHeight / cmChangeSize
.sngWidth = .sngWidth / cmChangeSize
imgPreview.Stretch = True
imgPreview.Move .sngLeft, .sngTop, .sngWidth, .sngHeight
'// 如果已经缩小了9倍则缩小按钮不可用
If .intZoon < -9 Then
Command1.Enabled = False
Command2.Enabled = True
Else
Command2.Enabled = True
End If
End With
End Sub
'// 放大
Private Sub Command2_Click()
With muPreviewSize
.intZoon = .intZoon + 1
.sngHeight = .sngHeight * cmChangeSize
.sngWidth = .sngWidth * cmChangeSize
imgPreview.Stretch = True
imgPreview.Move .sngLeft, .sngTop, .sngWidth, .sngHeight
'// 如果已经放大了9倍则放大按钮不可用
If .intZoon > 9 Then
Command2.Enabled = False
Command1.Enabled = True
Else
Command1.Enabled = True
End If
End With
End Sub
Private Sub Form_Load()
With muPreviewSize
.intZoon = 0
'// + 0.5 为Image的边框
.sngHeight = imgPreview.Height + 0.5
.sngWidth = imgPreview.Width + 0.5
.sngLeft = imgPreview.Left
.sngTop = imgPreview.Top
End With
End Sub
展开全部
用image(strenth设为flase)就可以了,把图片装入后重新按比例计算并设定(strenth=true)image的大小
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
loadpicture是调用图片,并不能控制它的大小
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
VB控件无此功能.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询