如何从 MapXtreme 样式制作位图

发布于 2024-07-15 04:11:53 字数 1179 浏览 10 评论 0原文

我已在 MapXtreme 论坛上发布了这个问题,但由于没有人在那里回答问题,我希望这里有人对此产品有一些经验(mapxtreme 是由制作 MapInfo 的人制作的 GIS SDK),

我正在开发 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;
    }

TIA

I have posted this question on The MapXtreme forum but since nobody ever answers questions there I am hoping someone here has some experience with this product (mapxtreme is a GIS SDK made by the people who make MapInfo)

I am working on a MapXtreme Desktop app and we need bitmaps of our features styles

I have tried two ways but all I get is a grey bitmap with a dark X.

here is the code I have used both ways are in the code but one is commented out:

    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;
    }

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

⊕婉儿 2024-07-22 04:11:53

在等待答案 - 并尝试了无数其他方法 - 都无济于事后,我决定“手动”完成这一切,即我只是在样式对象中查看它的颜色并绘制适合图层类型的位图(线或多边形)。

它不能处理所有情况,也不能处理线条样式或内部颜色,但它目前可以满足我的目的。

这是执行此操作的代码。

    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;
    }

After waiting for an answer - and trying countless other ways - all to no avail, I decided on doing it all 'by hand' ie I simply look in the style object get the colour of it and draw a bitmap appropriate for the layer type (line or polygon).

It doesnt handle every case and also doesnt handle line styles or interior colours but it serves my purposes for now.

here is the code that does it.

    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;
    }
如日中天 2024-07-22 04:11:53

第一个代码已经几乎可以工作了。 我只是稍微调整了一下就修复了它。
我已经测试了它的复合样式,其中包含 simplevectorpointstyle。

    /// <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;
    }

The first code already almost worked. I just tweaked it a little bit to fix it.
I have tested it for a composite style that contains a simplevectorpointstyle in it.

    /// <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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文