如何将Map中显示的图形转化成栅格文件
本例要实现的是如何将当前激活的Map中显示的图形转化成栅格文件。
l 要点
通过IMap实例获得IActiveView接口对象,定义IExporter接口变量,使用TiffExporter实现该接口并对其中的属性进行赋值,使用IActiveView.Output方法将Map中显示的图形导出。
主要用到IActiveView接口,IExporter接口和IEnvelope接口。
l 程序说明
函数Output将当前激活的Map中显示的图形转化成栅格文件,栅格文件路径及名称由参数sFileAllName确定。
l 代码
|
Private Sub Output(ByVal sFileAllName As String) Dim pMxDocument As IMxDocument Dim pActiveView As IActiveView Dim pExporter As IExporter Dim pEnvelope As IEnvelope Dim ptagRECT As tagRECT Dim pTrackCancel As ITrackCancel Dim lscreenResolution As Long On Error GoTo ErrorHandler: Set pMxDocument = ThisDocument Set pActiveView = pMxDocument.ActiveView lscreenResolution = pActiveView.ScreenDisplay.DisplayTransformation.Resolution ptagRECT.Top = 0 ptagRECT.Left = 0 ptagRECT.Right = pActiveView.Extent.Width ptagRECT.bottom = pActiveView.Extent.Height 'We must calculate the size of the user specified Rectangle in Device units 'Hence convert width and height Set pEnvelope = New Envelope pEnvelope.PutCoords ptagRECT.Left, ptagRECT.bottom, ptagRECT.Right, ptagRECT.Top Set pExporter = New TiffExporter pExporter.Resolution = lscreenResolution pExporter.ExportFileName = sFileAllName pExporter.PixelBounds = pEnvelope Set pTrackCancel = New CancelTracker pActiveView.Output pExporter.StartExporting, lscreenResolution, _ ptagRECT, pActiveView.Extent, pTrackCancel
pExporter.FinishExporting Exit Sub ErrorHandler: MsgBox Err.Description End Sub Private Sub UIButtonControl1_Click() Dim pVBProject As VBProject On Error GoTo ErrorHandler: Set pVBProject = ThisDocument.VBProject Output pVBProject.FileName & "\..\..\..\.." & "\data\MyTifFile.tif" Exit Sub ErrorHandler: MsgBox Err.Description End Sub |
浙公网安备 33010602011771号