xamarin 我试图使其显示的标记在MAUI中返回null

s1ag04yj  于 2023-04-18  发布在  其他
关注(0)|答案(1)|浏览(107)

我需要转换一个XAMARIN代码到MAUI系统。所以有一个图像,必须使它出现时,我已经搜索的东西。但图像返回空。我不知道为什么它返回空,路径文件夹是在代码中选择。但它仍然没有返回图像。

private static SymbolStyle CreateMarkerStyle(string embeddedResourcePath, double scale)
    {
        try
        {
            var bitmapId = GetBitmapIdForEmbeddedResource(embeddedResourcePath); //From here I`m trying to get the photo.
            return new SymbolStyle { BitmapId = bitmapId, SymbolScale = scale, SymbolOffset = new Offset(0, 256) };
        }
        catch (Exception ex)
        {

            throw ex;
        }
        
    }

从这里我回到这个代码。

public MemoryLayer SearchMarkerLayer
    {
        
        get
        {
            if (_markerLayer == null)
            {
                _markerLayer = new MemoryLayer
                {
                    Name = "Sorgu Sonuçları",
                    MaxVisible = BingMapsLayer.Resolutions[8],
                    IsMapInfoLayer = true,
                    Style = CreateMarkerStyle("AGROWORKS.MOBILE.Images.location-pin.svg", 0.1) // This is the image I`m trying to make it appear.
                };
            }

            return _markerLayer;
        }
    }

从那里我们回到这里:

private static int GetBitmapIdForEmbeddedResource(string imagePath)
    {
        try
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            var image = assembly.GetManifestResourceStream(imagePath); //And here is the path of my image file. 
            var bitmapId = BitmapRegistry.Instance.Register(image); //Which returns null.
            return bitmapId;
        }
        catch (Exception ex)
        {

            throw ex;
        }
        
    }
ehxuflar

ehxuflar1#

我在maui项目中测试了你的代码,它返回一个int值,而不是null。
我的代码:

Assembly assembly = Assembly.GetExecutingAssembly();
var image = assembly.GetManifestResourceStream("MauiApp39.Mobile.Image.dotnet_bot.svg");
var bitmap = BitmapRegistry.Instance.Register(image);

调试结果:

我的项目的结构:

注意:我使用了NugetPackage MapSui.Maui 4.0.0-bete.9,并将镜像的build action设置为Embedded resource。

相关问题