7,762
社区成员
发帖
与我相关
我的任务
分享
'说明:viewer 要绘图的picture控件;picture1 你要替换的图片;command1 绘制圆;command2 用图片替换
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Dim px As Long, py As Long, r As Long
Private Sub Command1_Click()
Viewer.Circle (px, py), r, RGB(255, 0, 0)
End Sub
Private Sub Command2_Click()
Dim rgn As Long
'创建一个圆形区域
rgn = CreateEllipticRgn(px - r + 1, py - r + 1, px + r + 1, py + r + 1)
'将区域选到viewer的设备环境中
SelectClipRgn Viewer.hdc, rgn
'把picture1的图片绘制到viewer,图片将只在圆形区域内显示
Viewer.PaintPicture Picture1.Picture, 0, 0
DeleteObject rgn
End Sub
Private Sub Form_Load()
'初始化圆的参数
px = Viewer.ScaleWidth / 2
py = Viewer.ScaleHeight / 2
r = 120
End Sub