문제

나는이 질문을 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;
    }

티아

도움이 되었습니까?

해결책

답을 기다린 후 - 수많은 다른 방법으로 시도한 후에는 모두 소용이 없습니다. 나는 '손으로'모든 것을 수행하기로 결정했습니다. 즉, 스타일 객체를 보면 그 색상을 얻고 레이어 유형에 적합한 비트 맵을 그립니다 ( 선 또는 다각형).

그것은 모든 케이스를 처리하지 않으며 라인 스타일이나 인테리어 색상을 처리하지는 않지만 현재 내 목적을 제공합니다.

다음은 코드입니다.

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

다른 팁

첫 번째 코드는 이미 거의 작동했습니다. 나는 그것을 고치기 위해 조금 조정했다. 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;
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top