剪裁光栅图像边界

AutoCAD ActiveX/VBA

 
剪裁光栅图像边界
 
 
 

本例在模型空间中添加光栅图像,然后根据剪裁边界来剪裁图像。本例使用 sample 目录中的 downtown.jpg 文件。如果没有此图像,或者此图像位于其他目录中,请为 imageName 变量插入有效的路径和文件名。

Sub Ch10_ClippingRasterBoundary()
    Dim insertionPoint(0 To 2) As Double
    Dim scalefactor As Double
    Dim rotationAngle As Double
    Dim imageName As String
    Dim rasterObj As AcadRasterImage
    
    imageName = "C:\AutoCAD\sample\downtown.jpg"
    insertionPoint(0) = 5
    insertionPoint(1) = 5
    insertionPoint(2) = 0
    scalefactor = 2
    rotationAngle = 0
    
    On Error GoTo ERRORHANDLER
    ' 在模型空间中创建光栅图像
    Set rasterObj = ThisDrawing.ModelSpace.AddRaster _
                    (imageName, insertionPoint, _
                     scalefactor, rotationAngle)
   ZoomAll
    ' 使用点数组建立剪裁边界
    Dim clipPoints(0 To 9) As Double
    clipPoints(0) = 6: clipPoints(1) = 6.75
    clipPoints(2) = 7: clipPoints(3) = 6
    clipPoints(4) = 6: clipPoints(5) = 5
    clipPoints(6) = 5: clipPoints(7) = 6
    clipPoints(8) = 6: clipPoints(9) = 6.75
    
    ' 剪裁图像
    rasterObj.ClipBoundary clipPoints
    
    ' 启用剪裁显示
    rasterObj.ClippingEnabled = True
    ThisDrawing.Regen acActiveViewport
    Exit Sub
    
ERRORHANDLER:
    MsgBox Err.Description
End Sub