c# - 在图像的特定位置显示对象
问题描述
我有一个位图,我试图在该位图图像的特定位置(基于 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
解决方案
推荐阅读
- php - 我有一个 PHP 脚本可以使用此代码发送电子邮件-
- python - TclError:CentOS 中没有显示名称和 $DISPLAY 环境变量
- c# - 如何隐藏 DataGridVew 行
- php - 将 xampp 指向公共文件夹/仅用于一个项目的不同文件夹
- javascript - 函数不会执行里面的查询
- perl - Perl - 变量的值不在条件下工作
- android - 从 Android Activity 导航到 Fragment
- typescript - 通过递归对象结构生成表示路径联合的元组类型
- java - Netty 有 Redis 库吗?
- javascript - 日期的正则表达式 无效的正则表达式