【问题标题】:How to draw a text on an image and how to use this image as my custom pin icon?如何在图像上绘制文本以及如何将此图像用作我的自定义图钉图标?
【发布时间】:2017-07-31 22:22:30
【问题描述】:

如何在图像上绘制文本以及如何将此图像用作我的自定义图钉图标?

我使用https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/map/中的官方代码 我可以使用自定义图钉图像作为图标来替换标准的谷歌地图图钉,但我想在这个自定义图钉上添加文本,然后使用我的新图钉(带有文本)到我的新自定义图钉图标。

这是我现在使用的代码

 foreach (var pin in customPins)

 {

       var marker = new MarkerOptions ();

       marker.SetPosition (new LatLng (pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));

       marker.SetTitle (pin.Pin.Label);

       marker.SetSnippet (pin.Pin.Address);

       marker.SetIcon (BitmapDescriptorFactory.FromResource (Resource.Drawable.pin));

  }

所以制造商 SetIcon 这个方法来获取我的 Rouscoure.Drawable 文件夹上的自定义图钉图标。在这个文件夹中,我存储了我的 pin.png 图像。 我正在努力在原始图钉图像中绘制文本。然后,如果我成功在我的 pin 上添加文本,我也不知道如何使用 SetIcon 或 InvokeIcon 加载我的新图像。

【问题讨论】:

    标签: xamarin xamarin.android


    【解决方案1】:

    主要思想是先创建一个画布,然后再创建一个绘画。然后将这两者结合在一起。

    当你用谷歌搜索时,有很多 Java 示例。您唯一需要做的就是如何将其转换为 Xamarin.Android。这应该很容易。

    示例如下: https://forums.xamarin.com/discussion/comment/236649/#Comment_236649

    【讨论】:

    • 谢谢。这很有帮助!
    • 没问题,如果您有任何问题,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多