ExportToJPEG
摘要
Exports the page layout or data frame of a map document (.mxd) to the Joint Photographic Experts Group (JPEG) format.
讨论
JPEG files are compressed image files. They support 24-bit color and can be substantially more compact than many other file types. The JPEG compression algorithm is lossy and is not as well suited for line drawings and other textual or iconic graphics, and thus the PNG and GIF formats are preferred for these types of images.
要导出单个数据框(而不是整个页面布局),可将 DataFrame 对象传给函数的 data_frame 参数。由于数据框导出不具有可提供高度和宽度信息的关联页面,所以必须通过 df_export_width 和 df_export_height 参数来提供此信息。
对于页面布局导出和数据框导出,控制生成图像图形质量的方式有所不同。导出页面布局时,通过更改 resolution 参数来控制图像细节。导出数据框时,保持 resolution 参数的默认值,更改 df_export_width 和 df_export_height 参数来更改图像细节。高度和宽度参数直接控制在导出文件中生成的像素数,且仅在导出数据框时使用。像素数较高的图像具有较高的图像细节。对于大多数页面布局导出,默认参数值应在第一次尝试时生成良好的结果和美观的导出图像。对于数据框导出,您可能需要对 df_export_width 和 df_export_height 值进行若干次试验,之后才能得到理想的结果。
World files are not generated for page layout exports; a referenced data frame must be provided or the export will fail.
Refer to the Exporting your map topic in ArcGIS Help for more detailed discussions on exporting maps.
语法
参数 | 说明 | 数据类型 |
map_document |
A variable that references a MapDocument object. | MapDocument |
out_jpeg |
A string that represents the path and file name for the output export file. | String |
data_frame |
A variable that references a DataFrame object. Use the string/constant "PAGE_LAYOUT" to export the map document's page layout instead of an individual data frame. (默认值为 PAGE_LAYOUT) | Object |
df_export_width |
A number that defines the width of the export image in pixels for a data frame export. df_export_width is only used when exporting a data frame. Exporting a page layout uses the map document page width instead of df_export_width. (默认值为 640) | Integer |
df_export_height |
A number that defines the height of the export image in pixels for a data frame export. df_export_height is only used when exporting a data frame. Exporting a page layout uses the map document page height instead of df_export_height. (默认值为 480) | Integer |
resolution |
A number that defines the resolution of the export file in dots per inch (DPI). (默认值为 96) | Integer |
world_file |
If set to True, a georeferenced world file is created. The file contains pixel scale information and real-world coordinate information. (默认值为 False) | Boolean |
color_mode |
This value specifies the number of bits used to describe color.
(默认值为 24-BIT_TRUE_COLOR) | String |
jpeg_quality |
This value (0–100) controls the amount of compression applied to the output image. For JPEG, image quality is adversely affected the more compression is applied. A higher quality (highest = 100) setting will produce sharper images and larger file sizes. A lower quality setting will produce more image artifacts and smaller files. (默认值为 100) | Integer |
progressive |
If set to True, a progressive JPEG file will be created. A progressive image is one that displays in a series of scans of increasing quality rather than displaying the whole image at once. (默认值为 False) | Boolean |
代码示例
This script opens a map document and exports the page layout to a JPEG file using default values for all options.
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") arcpy.mapping.ExportToJPEG(mxd, r"C:\Project\Output\Project.jpg") del mxd
This script will export a single data frame instead of the entire page layout, similar to exporting from data view in the ArcMap application. The default values for df_export_width and df_export_height are 640 and 480. By passing larger values for these parameters, we are able to produce an output image with higher detail. Setting world_file = True generates a georeferenced world file in the same directory as the output file.
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0] arcpy.mapping.ExportToJPEG(mxd, r"C:\Project\Output\ProjectDataFrame.jpg", df, df_export_width=1600, df_export_height=1200, world_file=True) del mxd