代码实现IMapcontrol当前视图输出为图片功能

时间:2022-04-13 13:01:20
 SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "保存输出图片";
dialog.Filter = "JPG文件(*.jpg)|*.jpg|BMP文件(*.bmp)|*.bmp||";
if (dialog.ShowDialog() == DialogResult.OK)
{
tagRECT grect;
string str = System.IO.Path.GetExtension(dialog.FileName).ToLower();
IExport export = null;
if (str == ".jpg")
{
export = new ExportJPEGClass();
}
else
{
export = new ExportBMPClass();
}
export.ExportFileName = dialog.FileName;
int num = 0x60;
int num2 = ;
export.Resolution = num2;
grect.left = ;
grect.top = ;
tagRECT deviceFrame = this.m_pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();//.DeviceFrame;
grect.right = (int) (((deviceFrame.right - deviceFrame.left) * num2) / ((double) num));
grect.bottom = (int) (((deviceFrame.bottom - deviceFrame.top) * num2) / ((double) num));
IEnvelope envelope = new EnvelopeClass();
envelope.PutCoords((double) grect.left, (double) grect.top, (double) grect.right, (double) grect.bottom);
export.PixelBounds = envelope;
int hdc = export.StartExporting();
double resolution = export.Resolution;
this.m_pMapControl.ActiveView.Output(hdc, (int) resolution, ref grect, null, null);
export.FinishExporting();
export.Cleanup();
}