您的位置:首页 > 其它

ArcGis Engine中实现对符号的预览图输出

2008-04-18 16:37 309 查看
ArcGis Engine中实现对符号的预览图输出
07-11-12 11:24:09 作者:Aji 出处:中国GIS资讯网
在ArcGis Engine中实现对符号的预览,生成预览图片。使用的时候只要调用SymbolToBitmp(符号,宽,高)就可以返回生成的图片了。关键代码如下:

//在ArcGis Engine中实现对符号的预览,生成预览图片。使用的时候只要调用SymbolToBitmp(符号,宽,高)就可以返回生成的图片了。关键代码如下:

public static System.Drawing.Bitmap SymbolToBitmp(ISymbol pSymbol, int iwidth, int iheight, int wd)
{
//根据高宽创建图象
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, wd);

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 static ESRI.ArcGIS.Geometry.IGeometry CreateSymShape(ISymbol pSymbol, IEnvelope pEnvelope, int wd)
{// 根据传入的符号以及外包矩形区域返回对应的几何空间实体(点,线、面)
//判断是否为“点”符号

if (pSymbol is IMarkerSymbol)
{
// 为“点”符号则返回IEnvelope的中心点
IArea pArea;
pArea = pEnvelope as IArea;
return pArea.Centroid as IGeometry;
}
else
{
//判断是否为“线”符号

if (pSymbol is ILineSymbol)
{

IPolyline IpLine = new PolylineClass();
IpLine.FromPoint.PutCoords(0, pEnvelope.YMax / 2);
IpLine.ToPoint.PutCoords(pEnvelope.Width, pEnvelope.YMax / 2);

return IpLine as IGeometry;
}
else
{
//直接返回一个IEnvelope矩形区域
IEnvelope pnewEnvelope = new EnvelopeClass();
pnewEnvelope.PutCoords(wd, wd, pEnvelope.Width - wd, pEnvelope.Height-wd);

return pnewEnvelope as IGeometry;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐