首页 新闻 会员 周边

.NET Core中使用CoreCompat出错:"A null reference or invalid value was found [GDI+ status: InvalidParameter]"

0
悬赏园豆:30 [已解决问题] 解决于 2018-02-16 20:16

在 .NET Core 中使用 CoreCompat 处理图片,代码如下:

public static Graphics GetGraphic(Image originImage, Bitmap newImage)
{
    newImage.SetResolution(originImage.HorizontalResolution, originImage.VerticalResolution);
    //...
}

在 linux 上运行时出现下面的错误:

A null reference or invalid value was found [GDI+ status: InvalidParameter]
   at System.Drawing.GDIPlus.CheckStatus(Status status)
   at System.Drawing.Bitmap.SetResolution(Single xDpi, Single yDpi)

CoreCompat 的 nuget 包版本是 CoreCompat.System.Drawing 1.0.0-beta006

请问如何解决?

dudu的主页 dudu | 高人七级 | 园豆:31007
提问于:2018-02-16 16:44
< >
分享
最佳答案
0

出现这个问题是由于 originImage.HorizontalResolution 与 originImage.VerticalResolution 的值为 0

dudu | 高人七级 |园豆:31007 | 2018-02-16 20:16
其他回答(1)
0

Try catch 返回 new 对象就可以啦

fishyue | 园豆:146 (初学一级) | 2018-02-19 22:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册