C # + arcengine custom range output as a raster image (JPG/BMP)

Source: Internet
Author: User
/// <Summary>
/// Print the output. Currently, this function is only applicable to JPEG and BMP formats.
/// </Summary>
/// <Param name = "pexport"> </param>
/// <Param name = "dresolution"> resolution </param>
/// <Param name = "outputpath"> output path </param>
/// <Param name = "pvisiblebounds"> Custom visible area </param>
Private void funexportimage (iexport pexport, double dresolution, string outputpath, ienvelope pvisiblebounds)
{
Ienvelope ppixelbounds;
ESRI. ArcGIS. display. tagrect outtagrect;
ESRI. ArcGIS. display. tagrect displaybounds = m_activeview.exportframe;
Double iscreenresolution;
If (pexport = NULL)
{
MessageBox. Show ("print type not specified ");
Return;
}

If (pvisiblebounds! = NULL) // custom box range
{
Idisplaytransformation pdisplaytransformation = m_activeview.screendisplay.displaytransformation;
Pdisplaytransformation. transformrect (pvisiblebounds, ref displaybounds, 8); // 8 represents esridisplaytransformenum. esritransformtodevice
}

If (pexport is iexportimage)
{
Iexportimage pexportimage = pexport as iexportimage;
Pexportimage. imagetype = esriexportimagetype. esriexportimagetypetruecolor;
}

Iscreenresolution = m_activeview.screendisplay.displaytransformation.resolution;

Double l_resolution = convert. todouble (domainresolution. value );

// ================================================ ====================================
//
// Method 1
//
// 1 cm contains 37.79524 pixels
// Double dpixel = 37.79524;
/// Calculate the number of records contained in 1 cm according to the input resolution.
// Double tempratio = l_resolution * dpixel/iscreenresolution;
//// Height of the output image
// Double tempbottom = (displaybounds. Bottom-displaybounds. Top) * tempratio;
//// Width of the output image
// Double tempright = (displaybounds. Right-displaybounds. Left) * tempratio + 0.1 * tempratio;
// ================================================ ======================================
//
// Method 2: currently feasible.
//
Double tempratio = l_resolution/iscreenresolution;
Double tempbottom = (displaybounds. Bottom-displaybounds. Top) * tempratio;
Double tempright = (displaybounds. Right-displaybounds. Left) * tempratio;
// ================================================ ====================================
Outtagrect. Left = 0;
Outtagrect. Top = 0;
Outtagrect. Bottom = convert. toint32 (math. truncate (tempbottom ));
Outtagrect. Right = convert. toint32 (math. truncate (tempright ));

Ppixelbounds = new envelopeclass ();
Ppixelbounds. putcoords (outtagrect. Left, outtagrect. Top, outtagrect. Right, outtagrect. Bottom );

Pexport. Resolution = dresolution;
Pexport. pixelbounds = ppixelbounds;
Pexport. exportfilename = outputpath;

Try
{
Itrackcancel ptrackcancel = new trackcancelclass ();
Int HDC;
HDC = pexport. startexporting ();

If (m_frmprobar = NULL) // m_frmprobar is the progress bar form
Funprogressbar ();
M_frmprobar.show ();

M_activeview.output (HDC, (INT) dresolution, ref outtagrect, pvisiblebounds, ptrackcancel );
Pexport. finishexporting ();

M_frmprobar.hide ();

If (dialogresult. Yes = MessageBox. Show ("plotting successful! \ N is saved in "+ txtoutputpath. Text +" \ n. Do I need to open the directory where the file is located? "," Prompt ", messageboxbuttons. yesno, messageboxicon. Information ))
{
System. Diagnostics. process. Start ("assumer.exe", txtoutputpath. Text );
}
Pexport. Cleanup ();
}
Catch
{
MessageBox. Show ("An error occurred while plotting! "," Warning ", messageboxbuttons. OK, messageboxicon. Warning );
// Release the variable
M_frmprobar = NULL;
Pexport = NULL;
Pvisiblebounds = NULL;
}
// Release the variable
Pexport = NULL;
Pvisiblebounds = NULL;

}

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.