导出透明背景色图片
透明原理:将TransparentColor属性的RGB设置为地图背景色一样的值,2个颜色叠加,得到透明效果
Code
Private Sub UIBtnCtl_ExportPNG_Click()
On Error GoTo PROC_ERROR
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Set pMxDocument = Application.Document
Set pMap = pMxDocument.FocusMap
Dim pAv As IActiveView
Set pAv = pMap
Dim pExport As IExport
Set pExport = New ExportPNG
Dim pPngExport As IExportPNG
Set pPngExport = New ExportPNG
pPngExport.TransparentColor.RGB = RGB(192, 230, 250)
pPngExport.TransparentColor.Transparency = 0
pPngExport.TransparentColor.NullColor = False
Set pExport = pPngExport
Dim pSavePath As String
pSavePath = "c:/pic.png"
Dim exportFrame As tagRECT
exportFrame = pAv.exportFrame
Dim hdc&, dpi&
Dim pEnv As IEnvelope
Set pEnv = New Envelope
pEnv.PutCoords exportFrame.Left, exportFrame.Top, exportFrame.Right, exportFrame.bottom
dpi = CLng(pExport.Resolution)
pExport.PixelBounds = pEnv
pExport.ExportFileName = pSavePath
pExport.Resolution = dpi
hdc = pExport.StartExporting
pAv.Output hdc, dpi, exportFrame, Nothing, Nothing
pExport.FinishExporting
MsgBox "导出完毕!"
Exit Sub
PROC_ERROR:
MsgBox Err.Description
End Sub
Private Sub UIBtnCtl_ExportPNG_Click()
On Error GoTo PROC_ERROR
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Set pMxDocument = Application.Document
Set pMap = pMxDocument.FocusMap
Dim pAv As IActiveView
Set pAv = pMap
Dim pExport As IExport
Set pExport = New ExportPNG
Dim pPngExport As IExportPNG
Set pPngExport = New ExportPNG
pPngExport.TransparentColor.RGB = RGB(192, 230, 250)
pPngExport.TransparentColor.Transparency = 0
pPngExport.TransparentColor.NullColor = False
Set pExport = pPngExport
Dim pSavePath As String
pSavePath = "c:/pic.png"
Dim exportFrame As tagRECT
exportFrame = pAv.exportFrame
Dim hdc&, dpi&
Dim pEnv As IEnvelope
Set pEnv = New Envelope
pEnv.PutCoords exportFrame.Left, exportFrame.Top, exportFrame.Right, exportFrame.bottom
dpi = CLng(pExport.Resolution)
pExport.PixelBounds = pEnv
pExport.ExportFileName = pSavePath
pExport.Resolution = dpi
hdc = pExport.StartExporting
pAv.Output hdc, dpi, exportFrame, Nothing, Nothing
pExport.FinishExporting
MsgBox "导出完毕!"
Exit Sub
PROC_ERROR:
MsgBox Err.Description
End Sub