这是在一个控件上再叠加一张图片的代码
如何对这两图片进行缩放呢?
比如说一个放大按钮,点下去就对大图进行1X,2X的放大
另一个小图的放大按钮,点下去对小图1x,2x的放大呢?
小图缩放仍应居中Private Sub Command1_Click()
Picture1.AutoRedraw = True
Picture1.ScaleMode = 3
Dim pic As StdPicture
Set Picture1.Picture = LoadPicture("e:\mc\mmtest.jpg") '大图
Set pic = LoadPicture("e:\mc\test.jpg") '小图
Dim h As Long, w As Long
h = ScaleY(pic.Height, vbHimetric, vbPixels)
w = ScaleY(pic.Width, vbHimetric, vbPixels)
Dim cx As Long
Dim cy As Long
If w > Picture1.ScaleWidth Then
cx = 0
Else
cx = (Picture1.ScaleWidth - w) / 2
End If
If h > Picture1.ScaleHeight Then
cy = 0
Else
cy = (Picture1.ScaleHeight - h) / 2
End If
Picture1.PaintPicture pic, cx, cy
Set Picture1.Picture = Picture1.Image
SavePicture Picture1.Image, "e:\mc\mtest.bmp"
End Sub
如何对这两图片进行缩放呢?
比如说一个放大按钮,点下去就对大图进行1X,2X的放大
另一个小图的放大按钮,点下去对小图1x,2x的放大呢?
小图缩放仍应居中Private Sub Command1_Click()
Picture1.AutoRedraw = True
Picture1.ScaleMode = 3
Dim pic As StdPicture
Set Picture1.Picture = LoadPicture("e:\mc\mmtest.jpg") '大图
Set pic = LoadPicture("e:\mc\test.jpg") '小图
Dim h As Long, w As Long
h = ScaleY(pic.Height, vbHimetric, vbPixels)
w = ScaleY(pic.Width, vbHimetric, vbPixels)
Dim cx As Long
Dim cy As Long
If w > Picture1.ScaleWidth Then
cx = 0
Else
cx = (Picture1.ScaleWidth - w) / 2
End If
If h > Picture1.ScaleHeight Then
cy = 0
Else
cy = (Picture1.ScaleHeight - h) / 2
End If
Picture1.PaintPicture pic, cx, cy
Set Picture1.Picture = Picture1.Image
SavePicture Picture1.Image, "e:\mc\mtest.bmp"
End Sub
这样的话,你必须保存原来的2个图象( 比如用2个picturebox, 你可以设置成不可见状态来隐藏;)
再用另一个picturebox来放组合后的图象. 只对其写, 或保存, 而不读!
而先前的2个原图picturebox 在loadpicture后只读而不写! 而你放大缩小的都差不多,都是: 原图picturebox ---> 组合picturebox . 方法paint就可以了
Dim tmpHei As Single, tmpWid As Single
With Pic1
Select Case InOrOut
Case 1
.ScaleHeight = .ScaleHeight / 1.5
.ScaleWidth = .ScaleWidth / 1.5
Case 2
.ScaleHeight = .ScaleHeight * 1.5
.ScaleWidth = .ScaleWidth * 1.5
End Select
.Cls
'.PaintPicture img1.Picture, .ScaleLeft / 1.5, .ScaleTop, img1.Width, img1.Height
.PaintPicture img1.Picture, (.ScaleWidth - img1.Width) / 2, (.ScaleHeight - img1.Height) / 2, img1.Width, img1.Height
End With
End SubPrivate Sub Pic1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ZoomPic (IIf(Button = 1, 1, 2))
End SubPrivate Sub Form_Load()
img1.Picture = LoadPicture(App.Path & "\2.jpg")
With Pic1
'.PaintPicture img1.Picture, .ScaleLeft / 1.5, .ScaleTop, img1.Width, img1.Height
.PaintPicture img1.Picture, (.ScaleWidth - img1.Width) / 2, (.ScaleHeight - img1.Height) / 2, img1.Width, img1.Height
End With
End Sub