默认头像
路人甲
路人甲
  • 注册日期2004-03-21
  • 发帖数89
  • QQ
  • 铜币494枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2232回复:4

地图输出成jpg或bmp

楼主#
更多 发布于:2004-10-11 08:14

在engine中,怎么杨把地图输出成jpg或bmp 要用到哪个接口

原来在8。3中的输出接口在engine中没有了,

喜欢0 评分0
默认头像
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2004-10-12 15:44

This sample demonstrates how to export the active view to any of the ten supported graphics file formats. Using this sample in its current state will export a JPEG file to C:\. You can easily modify it to produce other export formats, saved to a location of your choice. Products: ArcView: VBA, VC++

Platforms: Windows

Minimum ArcGIS Release: 9.0  

How to use: [VBA] Paste this code into the Visual Basic editor and select Run Sub from the Run menu. [VC++] Paste the function in your project. Call the function from your code.

[VBA] Public Sub ExportActiveView()   Dim pMxDoc As IMxDocument   Set pMxDoc = ThisDocument   Dim pActiveView As IActiveView   Set pActiveView = pMxDoc.ActiveView      'Create an ExportJPEG object and QI the pExport interface pointer onto it.   ' To export to a format other than JPEG, simply create a different CoClass here   ' and change the file extension of the ExportFileName.   Dim pExport As IExport   Set pExport = New ExportJPEG   pExport.ExportFileName = "C:\ExportTest1.jpg"

    'Set the export object resolution to 96 dpi.  The default screen resolution for   ' MS Windows is usually 96dpi, and this value is also the default resolution for all   ' of the ArcGIS image format exporters.  The vector format exporters (PDF, AI, etc.)   ' default to 300 dpi, so we should explicitly set resolution here to be certain we   ' are working with a resolution of 96.   pExport.Resolution = 96      'For both PageLayout and Map objects, the ExportFrame property always holds a tagRECT   ' structure appropriate for exporting.  The values in the tagRECT correspond to the width   ' and height to export, measured in pixels with an origin in the top left corner.   Dim exportRECT As tagRECT   exportRECT = pActiveView.ExportFrame      'Create a new envelope object and populate it with the values from exportRECT.   ' We need to do this because the exporter object requires an envelope object   ' instead of a tagRECT structure.   Dim pPixelBoundsEnv As IEnvelope   Set pPixelBoundsEnv = New Envelope   pPixelBoundsEnv.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, exportRECT.bottom      'Assign the envelope object to the exporter object's PixelBounds property.  The exporter object   ' will use these dimensions when allocating memory for the export file.   pExport.PixelBounds = pPixelBoundsEnv

 'Initialize the exporter object and store it's device context in the hDC variable.  At this method   ' call, the exporter object will create an empty file and allocate memory based on resolution,   ' bit depth, and pixel bounds.   Dim hDC As Long   hDC = pExport.StartExporting      'Redraw the active view, rendering it to the exporter object device context instead of the app display.   'We pass the following values:   ' * hDC is the device context of the exporter object.   ' * pExport.Resolution is 96, the default resolution value for all image export formats.  Default screen   ' resolution for MS Windows is usually 96dpi.   ' * exportRECT is the tagRECT structure that describes the dimensions of the view that will be rendered.   ' The values in exportRECT should match those held in the exporter object's PixelBounds property.   pActiveView.Output hDC, pExport.Resolution, exportRECT, Nothing, Nothing      'Finish writing the export file and cleanup any intermediate files.   pExport.FinishExporting   pExport.Cleanup    End Sub

Public Sub ExportActiveView2()   Dim pMxDoc As IMxDocument   Dim pActiveView As IActiveView   Dim pExport As IExport   Dim pPixelBoundsEnv As IEnvelope   Dim exportRECT As tagRECT   Dim iOutputResolution As Integer   Dim iScreenResolution As Integer   Dim hDC As Long

 Set pMxDoc = Application.Document   Set pActiveView = pMxDoc.ActiveView      Set pExport = New ExportJPEG

 pExport.ExportFileName = "C:\ExportTest2." ; Right(pExport.Filter, 3)

 'Because we are exporting to a resolution that differs from screen resolution, we should   ' assign the two values to variables for use in our sizing calculations   iScreenResolution = 96  'default screen resolution is usually 96dpi   iOutputResolution = 300   pExport.Resolution = iOutputResolution      'The ExportFrame property gives us the dimensions appropriate for an export at screen resolution.   ' Because we are exporting at a higher resolution (more pixels), we must multiply each dimesion   ' by the ratio of OutputResolution to ScreenResolution. Instead of assigning the entire   ' ExportFrame directly to the exportRECT, let's bring the values across one at a time and multiply   ' the dimensions.   With exportRECT     .Left = 0     .Top = 0     .Right = pActiveView.ExportFrame.Right * (iOutputResolution / iScreenResolution)     .bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution)   End With      'Set up the PixelBounds envelope to match the exportRECT   Set pPixelBoundsEnv = New Envelope   pPixelBoundsEnv.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, exportRECT.bottom   pExport.PixelBounds = pPixelBoundsEnv      hDC = pExport.StartExporting   pActiveView.Output hDC, pExport.Resolution, exportRECT, Nothing, Nothing   pExport.FinishExporting   pExport.Cleanup    End Sub [VC++] HRESULT ExportActiveView() {   IDocumentPtr ipDoc;   m_ipApp->get_Document(;ipDoc);   IMxApplicationPtr ipMxApp(m_ipApp);   IMxDocumentPtr ipMxDoc(ipDoc);   IActiveViewPtr ipActiveView;   ipMxDoc->get_ActiveView(;ipActiveView);

 // Create an ExportJPEG object and QI the pExport interface pointer onto it.   //  To export to a format other than JPEG, simply create a different CoClass here   //  and change the file extension of the ExportFileName.   IExportPtr ipExport(CLSID_ExportJPEG);   ipExport->put_ExportFileName(L"C:\\ExportTest1.jpg");

 // Set the export object resolution to 96 dpi.  The default screen resolution for   //  MS Windows is usually 96dpi, and this value is also the default resolution for all   //  of the ArcGIS image format exporters.  The vector format exporters (PDF, AI, etc.)   //  default to 300 dpi, so we should explicitly set resolution here to be certain we   //  are working with a resolution of 96.   ipExport->put_Resolution(96);

 // For both PageLayout and Map objects, the ExportFrame property always holds a tagRECT   //  structure appropriate for exporting.  The values in the tagRECT correspond to the width   //  and height to export, measured in pixels with an origin in the top left corner.   tagRECT exportRECT;   ipActiveView->get_ExportFrame(;exportRECT);

 // Create a new envelope object and populate it with the values from exportRECT.   //  We need to do this because the exporter object requires an envelope object   //  instead of a tagRECT structure.   IEnvelopePtr ipPixelBoundsEnv(CLSID_Envelope);   ipPixelBoundsEnv->PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);

 // Assign the envelope object to the exporter object's PixelBounds property.  The exporter object   //  will use these dimensions when allocating memory for the export file.   ipExport->put_PixelBounds(ipPixelBoundsEnv);

 // Initialize the exporter object and store it's device context in the hDC variable.  At this method   //  call, the exporter object will create an empty file and allocate memory based on resolution,   //  bit depth, and pixel bounds.   OLE_HANDLE hDC;   ipExport->StartExporting(;hDC);

 // Redraw the active view, rendering it to the exporter object device context instead of the app display.   // We pass the following values:   //  * hDC is the device context of the exporter object.   //  * pExport.Resolution is 96, the default resolution value for all image export formats.  Default screen   //  resolution for MS Windows is usually 96dpi.   //  * exportRECT is the tagRECT structure that describes the dimensions of the view that will be rendered.   //  The values in exportRECT should match those held in the exporter object's PixelBounds property.   double dResolution;   ipExport->get_Resolution(;dResolution);   ipActiveView->Output(hDC, (long)dResolution, ;exportRECT, 0, 0);

 // Finish writing the export file and cleanup any intermediate files.   ipExport->FinishExporting();   ipExport->Cleanup();

 return S_OK; }

HRESULT ExportActiveView2() {   IDocumentPtr ipDoc;   m_ipApp->get_Document(;ipDoc);   IMxApplicationPtr ipMxApp(m_ipApp);   IMxDocumentPtr ipMxDoc(ipDoc);   IActiveViewPtr ipActiveView;   ipMxDoc->get_ActiveView(;ipActiveView);

 IExportPtr ipExport(CLSID_ExportJPEG);   CComBSTR strFilter;   ipExport->get_Filter(;strFilter);   UINT uFilterLength(strFilter.Length() - 3);   CComBSTR strExtension(L"c:\\ExportTest2.");   strExtension += _tcsninc(strFilter, uFilterLength);

 ipExport->put_ExportFileName(strExtension);

 // Because we are exporting to a resolution that differs from screen resolution, we should   //  assign the two values to variables for use in our sizing calculations   int iScreenResolution = 96;  // default screen resolution is usually 96dpi   int iOutputResolution = 300;   ipExport->put_Resolution(iOutputResolution);

 // The ExportFrame property gives us the dimensions appropriate for an export at screen resolution.   //  Because we are exporting at a higher resolution (more pixels), we must multiply each dimesion   //  by the ratio of OutputResolution to ScreenResolution. Instead of assigning the entire   //  ExportFrame directly to the exportRECT, let's bring the values across one at a time and multiply   //  the dimensions.   tagRECT exportFrame;   ipActiveView->get_ExportFrame(;exportFrame);   tagRECT exportRECT;   exportRECT.left = 0;   exportRECT.top = 0;   exportRECT.right = exportFrame.right * (iOutputResolution / iScreenResolution);   exportRECT.bottom = exportFrame.bottom * (iOutputResolution / iScreenResolution);

 // Set up the PixelBounds envelope to match the exportRECT   IEnvelopePtr ipPixelBoundsEnv(CLSID_Envelope);   ipPixelBoundsEnv->PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);   ipExport->put_PixelBounds(ipPixelBoundsEnv);

 OLE_HANDLE hDC;   ipExport->StartExporting(;hDC);   double dResolution;   ipExport->get_Resolution(;dResolution);   ipActiveView->Output(hDC, (long)dResolution, ;exportRECT, 0, 0);   ipExport->FinishExporting();   ipExport->Cleanup();

 return S_OK; }

[此贴子已经被作者于2004-10-12 15:46:02编辑过]
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2004-03-21
  • 发帖数89
  • QQ
  • 铜币494枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-10-12 22:59

非常感谢gis !!!,

可能是我的问题没有说清楚,

在8.3和9.0中,IExport是存在的,但是在engine中,这个接口不存在了。

上面的代码,在独立的engine环境中,是不能使用的,我想在独立的engine环境中,实现我说的功能,

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数384
  • QQ
  • 铜币555枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2004-10-14 14:21
以下是引用tianjuan980106在2004-10-12 22:59:19的发言:

非常感谢gis !!!,

可能是我的问题没有说清楚,

在8.3和9.0中,IExport是存在的,但是在engine中,这个接口不存在了。

上面的代码,在独立的engine环境中,是不能使用的,我想在独立的engine环境中,实现我说的功能,

你查了帮助了么?这是我在9.0帮助中看到的:

IExport Interface (esriOutput)

Provides access to members that control the Export.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.
举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2004-03-21
  • 发帖数89
  • QQ
  • 铜币494枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2004-10-18 15:15

谢谢,我找到了,你说的是对的,

开始的时候,我是在ae的uml中找的,没有找到,但是在帮助中还是有的,

谢谢!!!

举报 回复(0) 喜欢(0)     评分
默认头像

返回顶部