ArcGIS Engine中实现对符号的输出预览
2010-02-02 11:48
211 查看
在ArcGis Engine中实现对符号的预览,生成预览图片。使用的时候只要调用SymbolToBitmp(符号,宽,高)就可以返回生成的图片了。关键代码如下:
public System.Drawing.Bitmap SymbolToBitmp(ESRI.ArcGIS.Display.ISymbol pSymbol,int iwidth,int iheight)
{
//根据高宽创建图象
Bitmap bmp = new Bitmap(iwidth,iheight);
Graphics gImage = Graphics.FromImage(bmp);
gImage.Clear(Color.White);
double dpi = gImage.DpiX;
IEnvelope pEnvelope = new EnvelopeClass();
pEnvelope.PutCoords(0,0,(double)bmp.Width,(double)bmp.Height);
tagRECT deviceRect;
deviceRect.left = 0;
deviceRect.right = bmp.Width;
deviceRect.top = 0;
deviceRect.bottom = bmp.Height;
IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();
pDisplayTransformation.VisibleBounds = pEnvelope;
pDisplayTransformation.Bounds = pEnvelope;
pDisplayTransformation.set_DeviceFrame(ref deviceRect);
pDisplayTransformation.Resolution = dpi;
IGeometry pGeo = CreateSymShape(pSymbol,pEnvelope);
System.IntPtr hdc = new IntPtr();
hdc = gImage.GetHdc();
//将符号的形状绘制到图象中
pSymbol.SetupDC((int)hdc,pDisplayTransformation);
pSymbol.Draw(pGeo);
pSymbol.ResetDC();
gImage.ReleaseHdc(hdc);
gImage.Dispose();
return bmp;
}
public ESRI.ArcGIS.Geometry.IGeometry CreateSymShape(ISymbol pSymbol,IEnvelope pEnvelope)
{// 根据传入的符号以及外包矩形区域返回对应的几何空间实体(点,线、面)
//判断是否为“点”符号
ESRI.ArcGIS.Display.IMarkerSymbol IMarkerSym;
IMarkerSym = pSymbol as IMarkerSymbol;
if (IMarkerSym != null)
{
// 为“点”符号则返回IEnvelope的中心点
IArea pArea ;
pArea = pEnvelope as IArea;
return pArea.Centroid as IGeometry;
}
else
{
//判断是否为“线”符号
ESRI.ArcGIS.Display.ILineSymbol IlineSym;
ESRI.ArcGIS.Display.ITextSymbol ITextSym;
IlineSym = pSymbol as ILineSymbol;
ITextSym = pSymbol as ITextSymbol;
if(IlineSym != null || ITextSym != null)
{
//返回45度的对角线
ESRI.ArcGIS.Geometry.IPolyline IpLine;
IpLine = new PolylineClass();
IpLine.FromPoint = pEnvelope.LowerLeft;
IpLine.ToPoint = pEnvelope.UpperRight;
return IpLine as IGeometry;
}
else
{
//直接返回一个IEnvelope矩形区域
return pEnvelope as IGeometry;
}
}
}
public System.Drawing.Bitmap SymbolToBitmp(ESRI.ArcGIS.Display.ISymbol pSymbol,int iwidth,int iheight)
{
//根据高宽创建图象
Bitmap bmp = new Bitmap(iwidth,iheight);
Graphics gImage = Graphics.FromImage(bmp);
gImage.Clear(Color.White);
double dpi = gImage.DpiX;
IEnvelope pEnvelope = new EnvelopeClass();
pEnvelope.PutCoords(0,0,(double)bmp.Width,(double)bmp.Height);
tagRECT deviceRect;
deviceRect.left = 0;
deviceRect.right = bmp.Width;
deviceRect.top = 0;
deviceRect.bottom = bmp.Height;
IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();
pDisplayTransformation.VisibleBounds = pEnvelope;
pDisplayTransformation.Bounds = pEnvelope;
pDisplayTransformation.set_DeviceFrame(ref deviceRect);
pDisplayTransformation.Resolution = dpi;
IGeometry pGeo = CreateSymShape(pSymbol,pEnvelope);
System.IntPtr hdc = new IntPtr();
hdc = gImage.GetHdc();
//将符号的形状绘制到图象中
pSymbol.SetupDC((int)hdc,pDisplayTransformation);
pSymbol.Draw(pGeo);
pSymbol.ResetDC();
gImage.ReleaseHdc(hdc);
gImage.Dispose();
return bmp;
}
public ESRI.ArcGIS.Geometry.IGeometry CreateSymShape(ISymbol pSymbol,IEnvelope pEnvelope)
{// 根据传入的符号以及外包矩形区域返回对应的几何空间实体(点,线、面)
//判断是否为“点”符号
ESRI.ArcGIS.Display.IMarkerSymbol IMarkerSym;
IMarkerSym = pSymbol as IMarkerSymbol;
if (IMarkerSym != null)
{
// 为“点”符号则返回IEnvelope的中心点
IArea pArea ;
pArea = pEnvelope as IArea;
return pArea.Centroid as IGeometry;
}
else
{
//判断是否为“线”符号
ESRI.ArcGIS.Display.ILineSymbol IlineSym;
ESRI.ArcGIS.Display.ITextSymbol ITextSym;
IlineSym = pSymbol as ILineSymbol;
ITextSym = pSymbol as ITextSymbol;
if(IlineSym != null || ITextSym != null)
{
//返回45度的对角线
ESRI.ArcGIS.Geometry.IPolyline IpLine;
IpLine = new PolylineClass();
IpLine.FromPoint = pEnvelope.LowerLeft;
IpLine.ToPoint = pEnvelope.UpperRight;
return IpLine as IGeometry;
}
else
{
//直接返回一个IEnvelope矩形区域
return pEnvelope as IGeometry;
}
}
}
相关文章推荐
- ArcGis Engine中实现对符号的预览图输出
- ArcGis Engine中实现对符号的预览图输出
- ArcEngine中实现对符号的预览图输出
- 在ArcGis Engine中实现对符号的预览,生成预览图片
- 使用AutoHotkey 实现MarkDown的英文符号输出
- 汇编实现16位有符号二进制数排序并输出
- loner_li 机试题 编写一个简单的计算器实现加减乘除:输入两个数字和一个运算符号,输出结果(注意容错性)
- 用一个函数实现将一行字符串中最短的单词输出。此行字符串从主函数传递给该函数。假设字符串中包含的单词以空格作为分隔符号,例如”Asia Games 2010 is held in GuangZhou.”,其中最短的单词是”is”和”in”。
- 多种方式实现字符串/无符号数反向输出_栈_递归_头尾指针
- 多种方式实现字符串/无符号数反向输出_栈_递归_头尾指针
- ArcGIS Engine下实现地图输出
- ArcGIS Engine下实现地图输出
- 使用位运算实现有符号的十进制正负数转二进制输出
- 请编写一个C函数,该函数可以实现将一个整数转为任意进制的字符串输出
- javascript实现input file上传图片预览效果
- js实现图片上传及预览---------------------->>兼容ie6-8 火狐以及谷歌
- web项目Log4j日志输出路径配置问题 问题描述:一个web项目想在一个tomcat下运行多个实例(通过修改war包名称的实现),然后每个实例都将日志输出到tomcat的logs目录下实例名命名的文
- ArcGIS教程:为地理处理任务定义输出符号系统
- [Win32]一个调试器的实现(九)符号模型