在Visual Studio for Mac中用C#语言读取JPEG图像时,出现System.PlatformNotSupportedException异常。

问题描述 投票:0回答:1

我如何使用Visual Studio for Mac在C#中读取一个JPEG文件到内存中?

我的代码。

using AppKit;
using Foundation;

namespace TouristFree
{
    [Register("AppDelegate")]
    public class AppDelegate : NSApplicationDelegate
    {
        public AppDelegate()
        {
        }

        public override void DidFinishLaunching(NSNotification notification)
        {
            var filename = "/Users/person/Desktop/image.jpeg";
            var image = System.Drawing.Image.FromFile(filename);   // <— error here
        }
    }
}

抛出System.PlatformNotSupportedException。

c# xamarin xamarin.mac
1个回答
0
投票

要在应用程序的bundle之外加载图像(从Mac文件系统)。

NSImage image = new NSImage("/Users/person/Desktop/image.jpeg")

re: 在C#代码中使用图像 (Xamarin.Mac)

© www.soinside.com 2019 - 2024. All rights reserved.