AE exports 2D and 3D scenes as image and image space data files (with source code)

Source: Internet
Author: User
In AE development, we often encounter the need to export the current scenario in map, scene, and globe as an image. below is my summary of the export method, where two-dimensional can be exported to the memory or hard disk, you can also export the space data file of the image, which can only be exported to the hard disk in 3D, with the source code (VB. net), the usage is detailed in summary, ^ _ ^
''' <Summary>
''' Two-dimensional export the current scenario is an image object (in memory)
''' </Summary>
''' <Param name = "pactiveview"> current activeview </param>
''' <Returns> image object </returns>
''' <Remarks> </remarks>
Public shared function exporttobmp (byval pactiveview as iactiveview) as system. Drawing. Image
Dim presolution as double = pactiveview. screendisplay. displaytransformation. Resolution
Dim pexport as iexport = new exportbmp
Pexport. Resolution = presolution
Dim devicerect as tagrect = pactiveview. screendisplay. displaytransformation. deviceframe
Dim pdriverbounds as ienvelope = new envelope
Pdriverbounds. putcoords (devicerect. Left, devicerect. Bottom, devicerect. Right, devicerect. Top)
Pexport. pixelbounds = pdriverbounds
Dim pcancel as itrackcancel = new canceltracker
Pactiveview. Output (pexport. startexporting, presolution, devicerect, pactiveview. Extent, pcancel)
Pexport. finishexporting ()
Dim pexportbmp as iexportbmp = pexport
Dim pimage as system. Drawing. Image = system. Drawing. image. fromhbitmap (pexportbmp. Bitmap)
Pexport. Cleanup ()
Return pimage
End Function
''' <Summary>
''' Two-dimensional export the current scenario is image files (on hard disk)
''' </Summary>
''' <Param name = "pfilepath"> full image path </param>
''' <Param name = "pexportpic"> image format objects (such as iexportbmp) </param>
''' <Param name = "pactiveview"> current view </param>
''' <Param name = "pcheckworldfile"> whether to export the image's space data file (worldfile) </param>
''' <Param name = "presolution"> image classification rate. The default value is 96. </param>
''' <Remarks> </remarks>
Private sub exporttopic (byval pfilepath as string, byval pexportpic as iexport, byval pactiveview as iactiveview, optional byval pcheckworldfile as Boolean = false, optional byval presolution as double = 0)
If presolution = 0 then presolution = pactiveview. screendisplay. displaytransformation. Resolution
Dim pexport as iexport = pexportpic
Pexport. exportfilename = pfilepath
Pexport. Resolution = presolution
Dim devicerect as tagrect = pactiveview. screendisplay. displaytransformation. deviceframe
Dim pdriverbounds as ienvelope = new envelope
Pdriverbounds. putcoords (devicerect. Left, devicerect. Bottom, devicerect. Right, devicerect. Top)
Pexport. pixelbounds = pdriverbounds
Dim pcancel as itrackcancel = new canceltracker
Pactiveview. Output (pexport. startexporting, presolution, devicerect, pactiveview. Extent, pcancel)
''The statement for exporting the data space file must be placed between startexporting and finishexporting; otherwise, the statement is invalid.
If typeof pexport is iexportimage then
If pcheckworldfile then
Dim pworldfile as iworldfilesettings = pexport
Pworldfile. outputworldfile = true
Pworldfile. mapextent = pactiveview. Extent
Dim pworldfile2 as iworldfilesettings2 = pexport
Pworldfile2.maprotation = pactiveview. screendisplay. displaytransformation. Rotation
End if
End if
Pexport. finishexporting ()
Pexport. Cleanup ()
End sub
''' <Summary>
''' 3D export the current scenario is an image file (on hard disk)
''' </Summary>
''' <Param name = "pfilepath"> full image path </param>
''' <Param name = "exporttype"> A custom enumeration, indicating whether it is scene or globe </param>
''' <Param name = "imagetype"> export the image type BMP or JPEG. </param>
''' <Remarks> </remarks>
Private sub exporttopic (byval pfilepath as string, byval exporttype as wsexportcontroltype, byval imagetype as esri3doutputimagetype)
Select case exporttype
Case wsexportcontroltype. wsexportscene
M_scenehookhelper.activeviewer.getscreenshot (imagetype, pfilepath)
Case wsexportcontroltype. wsexportglobe
M_globehookhelper.activeviewer.getscreenshot (imagetype, pfilepath)
End select
End sub

The following is a description of the spatial data format:

The first format:
1. X-scale (the size of a pixel)
2. Rotating items
3. Rotating items
4. Negative y-scale (size of one pixel)
5. Conversion items, that is, the X coordinate in the upper left corner
6. Conversion items, that is, Y coordinates in the upper left corner
Second format:
1. x resolution scale of a pixel in a map unit in the X direction
2. Translation volume
3. Rotation volume
4. negative value of the Y Resolution scale of a pixel in the map unit in the Y direction
5. x coordinate of 1 (top left) pixel
6. Y coordinate of pixel (top left)
Third format (en ):
1. pixel x size
2. rotation about the Y axis (usually 0.0)
3. rotation about of the X axis (usually 0.0)
4. Negative pixel y size
5. x coordinate of upper left pixel center
6. Y coordinate of upper left pixel center
Fourth format:
1. How many meters does each grid point be deleted in the row direction?
2. x Rotation Angle
3. Y-direction Rotation Angle
4. How many meters does one grid point be deleted in the column direction?
5. x coordinate at the top left
6. Y coordinate at the top left

The first and third types are basically the same. The first type is a bit simple!
Example of a jgw file:
0.05410594
0.0000 d
0.0000 B
-0.05410594 E
25.023009 C
102.766439 F
A = x-scale (the size of a pixel)
E = negative Y-scale (size of one pixel)
B, d = rotation item
C, F = Conversion item, that is, the X coordinate and Y coordinate in the upper left corner
Generally, four points are used for Image Correction. If the image is not reversed, the rotation item is 0.
Note: The coordinate system used in this example is WGS84.
Computing of A, B, C, and F has many opinions on the network. A little messy!
Here is a brief description of the calculation method I use:
1. Determine the coordinates of the two corners of the image:
Determine the coordinates in the lower left corner and the upper right corner of the image map file.
I did not include specific data here. I used variables to illustrate the problem.
Coordinates in the lower left corner: (x1, Y1)
Coordinates in the upper right corner: (X2, Y2)
Number of pixel lines in the image map: Col
Number of pixel columns in the image map: Row
2. Determine the coordinates in the upper left corner of the image file:
Coordinates in the upper left corner: (x1, Y2)
3. Determine the rotation items:
Generally, 0.000000 is used as the rotation item.
4. Calculate the pixel size between the X and Y directions:
Pixel size in the X direction: (x2-x1)/COL
Pixel size in Y direction: (y2-y1)/row * (-1)
5. The data in the final jgw file is:
X2-x1/COL
0.000000
0.000000
(Y2-y1)/row * (-1)
X1
Y2
Note: This example is based on the WGS84 coordinate system!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.