C# 画点

画点的方法:
方法一:
     用picGraphics.FillRectangle(new SolidBrush(fillColor), p.X, p.Y, 1, 1); 即用一个像素填充方法.
方法二:
    用gdi32.dll库中的SetPixel方法
     [DllImport("gdi32.dll")]
     private static extern int SetPixel(IntPtr hdc, int x1, int y1, int color);
获得指定点的颜色:
   用gdi32.dll库中的GetPixel方法
  [DllImport("gdi32.dll")]
   private static extern uint GetPixel(IntPtr hDC, int XPos, int YPos);
   下面给出一些图形操作的集合:
   

       #region 图形操作函数集合
       [DllImport("gdi32.dll")]
        private static extern uint GetPixel(IntPtr hDC, int XPos, int YPos);

        [DllImport("gdi32.dll")]
        private static extern int SetPixel(IntPtr hdc, int x1, int y1, int color);

               
        
        static public byte GetRValue(uint color)
        {
            return (byte)color;
        }
           
        static public byte GetGValue(uint color)
        {
            return ((byte)(((short)(color)) >> 8));
        }

        static public byte GetBValue(uint color)
        {
            return ((byte)((color) >> 16));
        }

        static public byte GetAValue(uint color)
        {
            return ((byte)((color) >> 24));
        }

        private  uint RGB(Color color)
        {
           
// 返回由RGB构成的32位uint
            uint R = color.R;
            uint G = color.G;
            uint B = color.B;
            G <<= 8;
            B <<= 16;
            return ((uint)(R|G|B));
        }
       
        public Color GetColor(Point p)
        {
            // 得到指定点的颜色RGB
            
            uint colorref = GetPixel(this.picGraphics.GetHdc(), p.X, p.Y); 
// picGraphics是我用picturePox类中的CreateGraphics方法创建的Graphics对象
            this.picGraphics.ReleaseHdc();
            byte Red = GetRValue(colorref);
            byte Green = GetGValue(colorref);
            byte Blue = GetBValue(colorref);
            return Color.FromArgb(Red, Green, Blue);
        }

        public void SetColor(Point p, Color fillColor)
        {
            SetPixel(this.picGraphics.GetHdc(), p.X, p.Y, (int)RGB(fillColor));
            this.picGraphics.ReleaseHdc();
        }
         #endregion

阅读更多
换一批

mapxtreme c# 画点问题

09-20

想实现在指定的经纬度处画点。现在的问题是设定的经纬度没用,只能在地图的中点画点,且只能画这一个点。rn希望大家帮我看看,谢谢。rn代码参考了网上的实例,如下:rn private void button3_Click(object sender, EventArgs e)rn rn MapInfo.Data.Catalog Cat = MapInfo.Engine.Session.Current.Catalog;rn TableInfoMemTable TmInfo = new TableInfoMemTable("Tm");rnrn TmTbl = Cat.GetTable("Tm"); rn if (TmTbl != null) rn Cat.CloseTable("Tm"); //如果表不为空,标明没有重名rnrn /构造GeometryColumn字段rn TmInfo.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(this.mapControl1.Map.GetDisplayCoordSys()));rn //构造Style类型Column字段rn TmInfo.Columns.Add(ColumnFactory.CreateStyleColumn());rn //构造String类型Column字段rn TmInfo.Columns.Add(ColumnFactory.CreateStringColumn("Name", 12));rn TmInfo.Columns.Add(ColumnFactory.CreateStringColumn("Loca", 50));rn //构造Int类型Column字段rn TmInfo.Columns.Add(ColumnFactory.CreateIntColumn("Indx"));rn TmInfo.TableTypernrn TmTbl = Cat.CreateTable(TmInfo); //创建临时表rnrn TmFlyr = new FeatureLayer(TmTbl); //创建临时图层rn this.mapControl1.Map.Layers.Add(TmFlyr); //将临时图层加入当前的MapXTreme图层当中rn DPoint Vpt; //定义一个点rn Vpt.x = -101.236401711274; //赋值(经纬度)rn Vpt.y = 20.6474803334433;rnrn //下面应该是将坐标点根据当前地图的坐标系进行了一次转换rn FeatureGeometry SVpt = new MapInfo.Geometry.Point(TmFlyr.CoordSys, new DPoint(Vpt.x, Vpt.y)) as FeatureGeometry;rnrn MapInfo.Styles.CompositeStyle Vcs = new MapInfo.Styles.CompositeStyle(new MapInfo.Styles.SimpleVectorPointStyle(37, Color.Red, 10)); //创建点样式rn Feature Vftr = new Feature(TmTbl.TableInfo.Columns); //创建图元rn Vftr.Geometry = SVpt; //设置图元属性rn Vftr.Style = Vcs;rn Vftr["Name"] = "KHT";rn Vftr["Loca"] = "Tianjin";rn Vftr["Indx"] = 1;rnrn TmTbl.InsertFeature(Vftr); //将图元加入表中rnrn

没有更多推荐了,返回首页