我已经在MapXtreme论坛上发布了这个问题,但是因为没有人在论坛上回答问题,所以我希望这里的人对这个产品有一些经验(mapxtreme是一个由制作MapInfo的人制作的GIS )
我正在MapXtreme桌面应用程序上工作,我们需要我们的要素样式的位图
我已经尝试了两种方法,但我得到的只是一个带有黑色X的灰色位图。
下面是我使用的代码,两种方式都在代码中,但其中一种被注释掉了:
public static Bitmap GetStyleBitmap(Style style)
{
var bm = new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
var rect = new System.Drawing.Rectangle(0, 0, 16, 16);
var ss = new StyleSample();
ss.Bounds = rect;
if (style is CompositeStyle)
{
ss.ApplyAreaStyle(((CompositeStyle)style).AreaStyle);
ss.ApplyLineStyle(((CompositeStyle)style).LineStyle);
}
if (style is AreaStyle)
{
ss.ApplyAreaStyle((AreaStyle)style);
}
if (style is SimpleLineStyle)
{
ss.ApplyLineStyle((SimpleLineStyle)style);
}
//using MapExport
var me = new MapExport(ss.Map);
var image = me.Export();
return new Bitmap(image);
//using StyleSample.DrawToBitmap
//ss.DrawToBitmap(bm, rect);
//return bm;
}提亚
发布于 2009-04-16 03:25:11
在等待了一个答案--并尝试了无数的其他方法--都无济于事之后,我决定“手工”完成所有的工作,即我只是简单地查看样式对象,得到它的颜色,然后绘制一个适合图层类型(线或多边形)的位图。
它不能处理每一种情况,也不能处理线条样式或内部颜色,但它目前可以满足我的目的。
下面是执行此操作的代码。
public static Bitmap GetStyleBitmap(FeatureLayer fl)
{
Feature f = GetFirstFeature(fl);
if (f == null) return null;
var style = f.Style;
Color c;
var bm = new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
PointF[] poly = new PointF[]
{
new PointF(2,5),
new PointF(5,2),
new PointF(14,7),
new PointF(14,14),
new PointF(2,14),
new PointF(2,4)
};
SimpleLineStyle line = null;
if (style is CompositeStyle)
line = ((CompositeStyle)style).AreaStyle.Border as SimpleLineStyle;
if (style is AreaStyle)
line = ((AreaStyle)style).Border as SimpleLineStyle;
if (line != null)
{
c = line.Color;
using (var gr = Graphics.FromImage(bm))
{
gr.DrawPolygon(new Pen(c, 2), poly);
}
return bm;
}
line = style as SimpleLineStyle;
if (line != null)
{
c = line.Color;
using (var gr = Graphics.FromImage(bm))
{
gr.DrawLine(new Pen(c, 2), new PointF(2,2), new PointF(14,14));
}
}
return bm;
}发布于 2009-11-18 21:26:02
第一个代码已经几乎可以工作了。我只是稍微调整了一下来修复它。我测试了它的复合样式,其中包含了一个简单的事件指针样式。
/// <summary>
/// Creates an icon for the specified style.
/// </summary>
/// <param name="style">The style.</param>
/// <returns></returns>
private static Bitmap CreateStyleIcon(Style style)
{
const int iconSize = 16; //the size of the icon
System.Drawing.Rectangle iconArea = new System.Drawing.Rectangle(0, 0, iconSize, iconSize); //a rectangle area for the icon
StyleSample ss = new StyleSample { Bounds = iconArea };
if (style is CompositeStyle)
{
CompositeStyle compsiteStyle = style as CompositeStyle;
if (compsiteStyle.AreaStyle != null) //do we have an area style?
{
ss.ApplyAreaStyle(compsiteStyle.AreaStyle);
}
if (compsiteStyle.LineStyle != null) //do we have an LineStyle style?
{
ss.ApplyLineStyle(compsiteStyle.LineStyle);
}
if (compsiteStyle.SymbolStyle != null) //do we have an SymbolStyle style?
{
ss.ApplySymbol(compsiteStyle.SymbolStyle);
}
}
if (style is AreaStyle)
{
ss.ApplyAreaStyle((AreaStyle)style);
}
if (style is BaseLineStyle)
{
ss.ApplyLineStyle((BaseLineStyle)style);
}
//draw the bitmap
Bitmap iconBitmap = new Bitmap(iconSize, iconSize, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//the bitmap to draw the icon to
ss.DrawToBitmap(iconBitmap, iconArea);
return iconBitmap;
}https://stackoverflow.com/questions/679588
复制相似问题