/// <summary>
/// 列印輸出.該功能目前測試只適用於JPEG,BMP.格式
/// </summary>
/// <param name="pExport"></param>
/// <param name="dResolution">解析度</param>
/// <param name="outputPath">輸出路徑</param>
/// <param name="pVisibleBounds">自訂可見地區</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("列印類型未指定");
return;
}
if(pVisibleBounds!=null) //自訂框範圍
{
IDisplayTransformation pDisplayTransformation = m_ActiveView.ScreenDisplay.DisplayTransformation;
pDisplayTransformation.TransformRect(pVisibleBounds, ref DisplayBounds, 8);//8代表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);
//=====================================================================
//
//方法一
//
//一厘米包含37.79524個像素
//double dPixel = 37.79524;
////按照設定輸入解析度計算一厘米所含的像素數
//double tempratio = l_resolution * dPixel / iScreenResolution;
////輸出圖形的高度
//double tempbottom = (DisplayBounds.bottom - DisplayBounds.top) * tempratio;
////輸出圖形的寬度
//double tempright = (DisplayBounds.right - DisplayBounds.left) * tempratio + 0.1 * tempratio;
//======================================================================
//
//方法二:暫時可行.
//
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為進度條表單
FunProgressBar();
m_frmProBar.Show();
m_ActiveView.Output(hDC, (int)dResolution, ref outtagRECT, pVisibleBounds, pTrackCancel);
pExport.FinishExporting();
m_frmProBar.Hide();
if (DialogResult.Yes == MessageBox.Show("出圖成功! \n圖片儲存在" + txtOutPutPath.Text+"\n是否需要開啟檔案所在的目錄?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
{
System.Diagnostics.Process.Start("explorer.exe", txtOutPutPath.Text);
}
pExport.Cleanup();
}
catch
{
MessageBox.Show("出圖失敗!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
//釋放變數
m_frmProBar = null;
pExport = null;
pVisibleBounds = null;
}
//釋放變數
pExport = null;
pVisibleBounds = null;
}