相关疑难解决方法(0)

NuGet System.Drawing.Common .NET 6 CA1416 此调用站点可在所有平台上访问。“Image.FromStream(Stream)”仅支持:“windows”

将 NuGet 升级System.Drawing.Common到 6.0.0 会导致以下错误:

CA1416 此调用站点可在所有平台上访问。“Image.FromStream(Stream)”仅在“windows”上受支持。

https://www.nuget.org/packages/System.Drawing.Common/

受影响的代码如下:

var drawingImage = System.Drawing.Image.FromStream(memstr);
Run Code Online (Sandbox Code Playgroud)

我们使用该库来访问该方法GetThumbnailImage

public byte[] GetThumbnailBytes(byte[] imageBytes)
{
    var thumbnailBytes = Array.Empty<byte>();

    using (MemoryStream memstr = new MemoryStream(imageBytes))
    {
        var drawingImage = System.Drawing.Image.FromStream(memstr);
        var thumbnailSize = GetThumbnailSize(drawingImage);

        var thumbnail = drawingImage.GetThumbnailImage(thumbnailSize.Width, thumbnailSize.Height, null, IntPtr.Zero);

        var ms = thumbnail.ToStream(drawingImage.RawFormat);

        thumbnailBytes = ms.ReadFully();
    }

    return thumbnailBytes;
}
Run Code Online (Sandbox Code Playgroud)

我们仅在 Azure 上托管应用程序,因此针对 Windows 是可以的,但替换GetThumbnailImage也是可以接受的。

.net c# .net-6.0

23
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

.net-6.0 ×1

c# ×1