delphi/C#实现,其他语言稍微改下就行了。AE的编码各个语言都差不多,这里也没用到某一语言的特性。
函数特点:
1.可以精确导出指定范围的图形要素
2.支持多格式.TIF, .EMF,.GIF,.PDF,.PNG,.SVG,.AI,.EPS,.jpg等
3.Tif格式导出时支持坐标信息导出,支持压缩格式选择
 
 
delphi 版:
{海龙 created
功能说明:指定地图窗口指定区域裁图
参数说明:
指定地图窗口pMap
指定范围裁图pExtent,如某一图形的envolope或map.extent之类的
输出图片文件名称strPicFile,根据后缀名判断裁出图片类型
输出图片dpi iOutResolution ,默认300
裁图时地图窗口需设置的比例尺 sMapBLC ,可以为空
bGeoTiff 文件类型为tif时有效,为true时保存坐标信息
pTifCompressionType 文件类型为tif时有效,tif的压缩类型,默认无损
} function ClipMap2Pic(pMap: IMap;pExtent: IEnvelope; strPicFile: String; iOutResolution: Integer = ; sMapBLC: String = '';
bGeoTiff : Boolean = False; pTifCompressionType: esriTIFFCompression = esriTIFFCompressionNone):Boolean;
var
pAV: IActiveView;
pEnvNew: IEnvelope;
ptagTmp: tagRECT;
pExport: IExport;
ihdc, iPrevOutputImageQuality: Integer;
dRes: Double;
dWidth, dHeight, dMapBLC: Double;
tmpDC: HDC;
iScreenResolution: Integer;
deviceRECT: tagRECT;
pSD: IScreenDisplay;
pDT: IDisplayTransformation;
sWJLX: string;
//地图距离转屏幕像素数,不同缩放比例尺下同样距离对应像素数不同的,有特殊需要时设置sMapBLC
function ConvertMapUnitsToPixels(pAV: IActiveView;dMapUnits: Double):double;
var
pBounds: IEnvelope;
pDeviceFrame: tagRECT;
iDeviceRight, iDeviceLeft, iPixelExtent: integer;
dRealWorldExtent, dSizeOfEachPixel: double;
begin
Result:= ;
pDT.Get_DeviceFrame(pDeviceFrame);
iDeviceLeft:= pDeviceFrame.left;
iDeviceRight:= pDeviceFrame.right;
iPixelExtent:= iDeviceRight-iDeviceLeft;
pDT.Get_VisibleBounds(pBounds);
pBounds.Get_Width(dRealWorldExtent);
dSizeOfEachPixel:= dRealWorldExtent / iPixelExtent;
Result:= dMapUnits/dSizeOfEachPixel ;
end;
begin
Result:= False;
if pMap = nil then Exit;
if strPicFile = '' then Exit;
try
if FileExists(strPicFile) then
DeleteFile(PChar(strPicFile));
if (sMapBLC <> '') and TryStrToFloat(sMapBLC, dMapBLC) and (dMapBLC > ) then
pMap.Set_MapScale(StrToFloatEx(sMapBLC));//map的比例尺调整为出图比例尺
pAV:= pMap as IActiveView; sWJLX := UpperCase(RightStr(strPicFile, ));
if sWJLX = '.TIF' then //根据文件名后4位判断输出类型
pExport := CoExportTiff.Create as IExport
else
if sWJLX = '.EMF' then
pExport := CoExportEMF.Create as IExport
else
if sWJLX = '.BMP' then
pExport := CoExportBMP.Create as IExport
else
if sWJLX = '.GIF' then
pExport := CoExportGIF.Create as IExport
else
if sWJLX = '.PDF' then
pExport := CoExportPDF.Create as IExport
else
if sWJLX = '.PNG' then
pExport := CoExportPNG.Create as IExport
else
if sWJLX = '.SVG' then
pExport := CoExportEMF.Create as IExport
else
if RightStr(sWJLX, ) = '.AI' then
pExport := CoExportAI.Create as IExport
else
if sWJLX = '.EPS' then
pExport := CoExportPS.Create as IExport
else
pExport := CoExportJPEG.Create as IExport; pAV.Get_ScreenDisplay(pSD);
pSD.Get_DisplayTransformation(pDT);
(pDT as IOutputRasterSettings).Get_ResampleRatio(iPrevOutputImageQuality); tmpDC:= GetDC();
iScreenResolution:= GetDeviceCaps(tmpDC, ); //获取屏幕dpi
ReleaseDC(, tmpDC); // 根据传入的pExtent确定裁图的画布大小(出图比例尺下裁图范围的像素高和宽)
pExtent.Get_Width(dWidth);
pExtent.Get_Height(dHeight);
ptagTmp.left := ; //ptagTmp的right和bottom非常主要
ptagTmp.top := ;
ptagTmp.right := trunc(ConvertMapUnitsToPixels(pAV,dWidth) * iOutResolution / iScreenResolution); //把地图距离转为屏幕像素个数
ptagTmp.bottom := trunc(ConvertMapUnitsToPixels(pAV,dHeight) * iOutResolution / iScreenResolution); pEnvNew:= CoEnvelope.Create as IEnvelope;
pEnvNew.PutCoords(ptagTmp.left,ptagTmp.top,ptagTmp.right,ptagTmp.bottom); //裁图的画布大小 pExport.Set_ExportFileName(strPicFile);
pExport.Set_Resolution(iOutResolution);
pExport.Set_PixelBounds(pEnvNew);
if sWJLX = '.TIF' then
begin
if bGeoTiff then
begin
(pExport as IExportTIFF).Set_GeoTiff(True);//包含tif文件坐标信息,这2句是必须的
(pExport as IWorldFileSettings).Set_MapExtent(pExtent);
end;
(pExport as IExportTIFF).Set_CompressionType(pTifCompressionType);
end; if sWJLX = '.PDF' then
begin
(pExport as IExportPDF).Set_Compressed(True);
(pExport as IExportPDF).Set_EmbedFonts(True);
(pExport as IExportPDF).Set_ImageCompression(esriExportImageCompressionNone);
end; pExport.StartExporting(ihdc);
pAV.Output(ihdc, iOutResolution, ptagTmp, pExtent, nil);
pExport.FinishExporting; pExport.Cleanup;
(pDT as IOutputRasterSettings).Set_ResampleRatio(iPrevOutputImageQuality); if FileExists(strPicFile) then
Result:= True;
except
Result:= False;
end;
end;
 
C#版本:
/* GDI delegate to GetDeviceCaps function */

        [DllImport("GDI32.dll")]

        public static extern int GetDeviceCaps(int hdc, int nIndex);

        /* User32 delegates to getDC and ReleaseDC */

        [DllImport("User32.dll")]

        public static extern int GetDC(int hWnd);

        [DllImport("User32.dll")]

        public static extern int ReleaseDC(int hWnd, int hDC);

        [DllImport("user32.dll", SetLastError = true)]

        static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni);

        /// <summary>

        /// 地图距离转屏幕像素数,不同缩放比例尺下同样距离对应像素数不同的,有特殊需要时设置sMapBLC

        /// </summary>

        /// <param name="pAV">The p AV.</param>

        /// <param name="dMapUnits">地图距离</param>

        /// <returns></returns>

        public static double ConvertMapUnitsToPixels(IActiveView pAV, double dMapUnits)

        {

            IDisplayTransformation pDT = pAV.ScreenDisplay.DisplayTransformation;

            tagRECT pDeviceFrame = pDT.get_DeviceFrame();

            int iDeviceLeft = pDeviceFrame.left;

            int iDeviceRight = pDeviceFrame.right;

            int iPixelExtent = iDeviceRight-iDeviceLeft;

            double dRealWorldExtent = pAV.Extent.Width;

            double dSizeOfEachPixel = dRealWorldExtent / iPixelExtent;

            return dMapUnits / dSizeOfEachPixel;

        }

        /// <summary>

        /// 指定范围裁剪图片

        /// </summary>

        /// <param name="pMap">裁图地图窗口</param>

        /// <param name="pExtent">指定裁图范围</param>

        /// <param name="strPicFile">输出文件名称</param>

        /// <param name="iOutResolution">输出DPI</param>

        public static void ClipMap2Pic(IMap pMap, IEnvelope pExtent, string strPicFile, int iOutResolution, double blc, bool withWarning)

        {

            if (pMap == null) return;

            if (strPicFile == string.Empty) return;

            if (File.Exists(strPicFile))

            {

                if ((!withWarning) || (withWarning && (GtMap.GxFrame.GxFrameLib.Common.AxMessageBox.ShowConfirmation("图片已存在,是否覆盖?") == System.Windows.Forms.DialogResult.Yes)))

                    File.Delete(strPicFile);

                else

                    return;

            }

            IActiveView pAV = pMap as IActiveView;

            string sWJLX = strPicFile.Substring(strPicFile.Length - ).ToUpper();

            IExport pExport = null; 

            if (sWJLX == ".TIF")            //根据文件名后4位判断输出类型

                pExport = new ExportTIFFClass();

            else

            if (sWJLX == ".EMF")

                pExport = new ExportEMFClass();

            else

            if (sWJLX == ".BMP")

                pExport = new ExportBMPClass();

            else

            if (sWJLX == ".GIF")

                pExport = new ExportGIFClass();

            if (sWJLX == ".PDF")

                pExport = new ExportPDFClass();

            else

            if (sWJLX == ".PNG")

                pExport = new ExportPNGClass();

            else

            if (sWJLX == ".SVG")

                pExport = new ExportSVGClass();

            else

            if (strPicFile.Substring(strPicFile.Length - ).ToUpper() == ".AI")

                pExport = new ExportAIClass();

            else

            if (sWJLX == ".EPS")

                pExport = new ExportPSClass();

            else

                pExport = new ExportJPEGClass();

            IDisplayTransformation pDT = pAV.ScreenDisplay.DisplayTransformation;

            IOutputRasterSettings docOutputRasterSettings = pDT as IOutputRasterSettings;

            int iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;

            docOutputRasterSettings.ResampleRatio = ;  ////这个似乎没什么用

            //获取屏幕dpi

            /* Get the device context of the screen */

            long tmpDC = GetDC();

            /* Get the screen resolution. */

            int iScreenResolution = GetDeviceCaps((int)tmpDC, ); //88 is the win32 const for Logical pixels/inch in X)

            /* release the DC. */

            ReleaseDC(, (int)tmpDC);

            // 根据传入的pExtent确定裁图的画布大小(出图比例尺下裁图范围的像素高和宽)

            tagRECT ptagTmp;

            ptagTmp.left = ; //ptagTmp的right和bottom非常主要

            ptagTmp.top = ;

            ptagTmp.right = (int)Math.Truncate(ConvertMapUnitsToPixels(pAV,pExtent.Width) * iOutResolution / iScreenResolution); //把地图距离转为屏幕像素个数

            ptagTmp.bottom = (int)Math.Truncate(ConvertMapUnitsToPixels(pAV,pExtent.Height) * iOutResolution / iScreenResolution);

            IEnvelope pEnvNew = new EnvelopeClass();

            pEnvNew.PutCoords(ptagTmp.left,ptagTmp.top,ptagTmp.right,ptagTmp.bottom); //裁图的画布大小

            pExport.ExportFileName = strPicFile;

            pExport.Resolution = iOutResolution;

            pExport.PixelBounds = pEnvNew;

            if (sWJLX == ".TIF")

            {

                (pExport as IExportTIFF).GeoTiff = true;//包含tif文件坐标信息,这2句是必须的

                (pExport as IWorldFileSettings).MapExtent = pExtent;

                (pExport as IExportTIFF).CompressionType = esriTIFFCompression.esriTIFFCompressionJPEG;

            }

            if (sWJLX == ".PDF")

            {

              (pExport as IExportPDF).Compressed = true;

              (pExport as IExportPDF).EmbedFonts = true;

              (pExport as IExportPDF).ImageCompression = esriExportImageCompression.esriExportImageCompressionNone;

            }

            int ihdc = pExport.StartExporting();

            pAV.Output(ihdc, iOutResolution, ref ptagTmp, pExtent, null);

            pExport.FinishExporting();

            pExport.Cleanup();

            (pDT as IOutputRasterSettings).ResampleRatio = iPrevOutputImageQuality;

            if (!File.Exists(strPicFile) && withWarning)

                GtMap.GxFrame.GxFrameLib.Common.AxMessageBox.ShowInformation("图片导出失败!");

        }

//created by jhlong http://jhlong12345.blog.163.com/

ArcEngine地图窗口指定区域导出指定DPI多格式---delphi/C#实现的更多相关文章

  1. 微信小程序导出当前画布指定区域的内容并生成图片保存到本地相册(canvas)

    最近在学小程序,在把当前画布指定区域的内容导出并生成图片保存到本地这个知识点上踩坑了. 这里用到的方法是: wx.canvasToTempFilePath(),该方法作用是把当前画布指定区域的内容导出 ...

  2. 地图 SDK 系列教程-在地图上展示指定区域(转载)

    腾讯位置服务地图SDK是一套提供多种地理位置服务的应用程序接口.通过调用该接口,开发者可以在自己的应用中加入地图相关的功能(如地图展示.标注.绘制图形等),轻松访问腾讯地图服务和数据,构建功能丰富.交 ...

  3. web页面实现指定区域打印功能

    web页面实现指定区域打印功能 使用CSS,定义一个.noprint的class,将不打印的内容放入这个class内. 详细如下: <style media=print type="t ...

  4. 打印web页面指定区域的三种方法

    本文和大家分享一下web页面实现指定区域打印功能的三种方法,一起来看下吧. 第一种方法:使用CSS 定义一 个.noprint的class,将不打印的内容放入这个class内. 代码如下: <s ...

  5. Android DIY之路 (一) 指定区域多图片合成 放大 缩小 镜像 旋转 等(转)

    惯例先看效果图 // 注意做类似这种模板功能时候 方位由后台数据提供,这里我们用假数据 4个点 或者xy 加区域来做示例 //一开始我们公司用的是透明盖住 操作图片 但发现 局限性较大.后来直接限定区 ...

  6. html2canvas实现截取指定区域或iframe的区域

    官网文档: http://html2canvas.hertzen.com/ 使用的是 jquery 3.2.1   html2canvas 1.0.0-rc.7 截取根据id的指定区域: var ca ...

  7. img只显示图片一部分 或 css设置背景图片只显示图片指定区域

    17:14 2016/3/22img只显示图片一部分 或 css设置背景图片只显示图片指定区域 background-position: 100% 56%; 设置背景图片显示图片的哪个坐标区域,图片左 ...

  8. MySQL 如何只导出 指定的表 的表结构和数据 ( 转 )

    MySQL 如何只导出 指定的表 的表结构和数据 ( 转 ) 2011-01-04 15:03:33 分类: MySQL MySQL 如何只导出 指定的表 的表结构和数据 导出更个库的表结构如下:my ...

  9. 从SVN导出指定版本号之间修改的文件

    当一个网站项目进入运营维护阶段以后,不会再频繁地更新全部源文件到服务器,这个时间的修改大多是局部的,因此更新文件只需更新修改过的文件,其他 没有修改过的文件就没有必要上载到服务器.但一个稍微上规模的网 ...

随机推荐

  1. ajax请求技术

    1.写在前面: 阅读要求: 具有一定的HTML.CSS.JavaScript.Json基础 2.什么是ajax Ajax:即”Asynchronous Javascript And XML”(异步Ja ...

  2. 利用 spring bean 的属性 init-method 解决因为数据库连接没有初始化而导致首次点击页面超慢的问题

    问题的描述: 一个项目,涉及到了 两个数据源,分别使用的是 两个不同的 数据库连接池,其中一个是 poxool 连接池,问题在于,spring在启动时,只初始化其中的一个 数据库连接池中的数据库连接, ...

  3. Migrate Instance 操作详解 - 每天5分钟玩转 OpenStack(40)

    Migrate 操作的作用是将 instance 从当前的计算节点迁移到其他节点上. Migrate 不要求源和目标节点必须共享存储,当然共享存储也是可以的. Migrate 前必须满足一个条件:计算 ...

  4. CentOS安装LNMP环境的基础组件

    注:以下所有操作均在CentOS 6.5 x86_64位系统下完成. 在安装LNMP环境之前,请确保已经使用yum安装了以下各类基础组件(如果系统已自带,还可以考虑yum update下基础组件): ...

  5. Zabbix监控VMare Vcenter

    1.参照Zabbix文档配置 依照官方文档配置,没什么说的. zabbix官方文档:https://www.zabbix.com/documentation/3.2/manual/vm_monitor ...

  6. ASP.NET全局错误处理和异常日志记录以及IIS配置自定义错误页面

    应用场景和使用目的 很多时候,我们在访问页面的时候,由于程序异常.系统崩溃会导致出现黄页.在通常的情况下,黄页对于我们来说,帮助是极大的,因为它可以帮助我们知道问题根源,甚至是哪一行代码出现了错误.但 ...

  7. webhdfs 使用shell下载文件

    echo "test web hdfs how to use" >> foo.txt hdfs dfs -put foo.txt / HDFS启用webhdfs之后,可 ...

  8. [转]ASP.NET Core 之 Identity 入门(二)

    本文转自:http://www.cnblogs.com/savorboard/p/aspnetcore-identity2.html 前言 在 上篇文章 中讲了关于 Identity 需要了解的单词以 ...

  9. 【CSS】过渡、动画和变换

    1. 使用过渡 过渡效果一般是由浏览器直接改变元素的CSS属性实现的.例如,如果使用:hover选择器,一旦用户将鼠标悬停在元素之上,浏览器就会应用跟选择器关联的属性. <!DOCTYPE ht ...

  10. [转载]python中的sys模块(二)

    #!/usr/bin/python # Filename: using_sys.py import sys print 'The command line arguments are:' for i ...