首页 > 解决方案 > 在图像的特定位置显示对象

问题描述

我有一个位图,我试图在该位图图像的特定位置(基于 X 和 Y)上显示用户控件对象,您有什么解决方案吗?

实际上我使用了具有特定扩展名(* .ECW)的地图文件。我也可以在特定位置添加椭圆或绘制图像,但我会添加特定组件(例如,作为用户控件创建的按钮)。对不起这个无法执行的代码。假设我们有一个以图片或地图作为背景的图形对象。现在我们必须将组件添加到特定点。我画了一个这样的椭圆

ImageLayout BackgroundImageLayout;
protected Bitmap Background;
int  ppiRadius =100;

Background = new Bitmap(Width, Height);
BackgroundImageLayout = ImageLayout.Center;
// Set up the map bitmap
// Get a graphics obejct for the bitmap
var graphics = Graphics.FromImage(Background);
graphics.FillRectangle(new SolidBrush(System.Drawing.Color.Black), 0, 0, 
                          Width, Height);
// Draw the layers to the bitmap
var hdc = graphics.GetHdc();
if (_allLayersHandle != null)
    {
     foreach (var v in _allLayersHandle)
     {
     LastError = GlobalMapperDLL.GM_DrawLayer(hdc, v.Value, 
    ref _currentViewRect, 0, 0,

     Background.Width, Background.Height);
                }
            }
 graphics.ReleaseHdc(hdc); 
 if (LastError != GlobalMapperDLL.GM_Error_t32.GM_Error_None) return;

 _centerPoint = GISConvert.GetCenterPixel();
 graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;                
 var point = GISConvert.LatLonToPixel(sitePosition);      
  graphics.DrawEllipse(new System.Drawing.Pen(System.Drawing.Brushes.Red, 2), new RectangleF((point.X - ppiRadius / 2), (point.Y - ppiRadius / 2), ppiRadius, ppiRadius));
//or  graphics.DrawImage

标签: c#wpf

解决方案


推荐阅读