/// <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;
}