我使用GMaps在c#上使用谷歌地图。我写下纬度和经度值,然后按下加载按钮。然后代码在该点上打上一个标记(如箭头(。我想像谷歌地图一样旋转任何程度的标记。我没有任何传感器,所以我可以在文本框中写下学位,然后按下旋转按钮。我该怎么做?这段代码展示了我如何创建标记并将它们放入地图中。我知道位图一点,但不太多,很抱歉我的英语不好。我希望你能理解我想要什么。
`double lat = Convert.ToDouble(txtLat.Text);
double lng = Convert.ToDouble(txtLong.Text);
map.Position = new PointLatLng(lat, lng);
//custom marker
Bitmap bmpMarker = (Bitmap)Image.FromFile("img/arrow.png");
PointLatLng point = new PointLatLng(lat, lng);
GMap.NET.WindowsForms.GMapMarker marker = new GMarkerGoogle(point, bmpMarker);
//1. Create a Overlay
GMapOverlay markers = new GMapOverlay("markers");
map.ZoomAndCenterMarkers("markers");
//2. Add all available markers to that Overlay
markers.Markers.Add(marker);
//3. Cover map with Overlay
map.Overlays.Add(markers);
//RotateImage(bmpMarker, 180.0f);
marker.ToolTipText = map.Position.ToString();`
尝试通过旋转再次设置位图图像,因为它不是引用类型:
GMap.NET.WindowsForms.GMapMarker marker = new GMarkerGoogle(point, RotateImg(bmpMarker,45));
建议旋转位图:
public Bitmap RotateImg(Bitmap bmpimage, float angle)
{
int w = bmpimage.Width;
int h = bmpimage.Height;
PixelFormat pf;
pf = bmpimage.PixelFormat;
Bitmap tempImg = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tempImg);
g.DrawImageUnscaled(bmpimage, 1, 1);
g.Dispose();
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0.0F, 0.0F, w, h));
Matrix mtrx = new Matrix();
mtrx.Rotate(angle);
RectangleF rct = path.GetBounds(mtrx);
Bitmap newImg = new Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf);
g = Graphics.FromImage(newImg);
g.TranslateTransform(-rct.X, -rct.Y);
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawImageUnscaled(tempImg, 0, 0);
g.Dispose();
tempImg.Dispose();
return newImg;
}