简体   繁体   English

将 ImageSharp.Image 转换为 ImageSharp.PixelFormats.Rgba32?

[英]Convert ImageSharp.Image to ImageSharp.PixelFormats.Rgba32?

I am following a tutorial ( https://opentk.net/learn/chapter1/4-textures.html ) using ImageSharp.我正在使用 ImageSharp 学习教程( https://opentk.net/learn/chapter1/4-textures.html )。 How do I convert the type 'ImageSharp.Image' to 'ImageSharp.PixelFormats.Rgba32'?如何将“ImageSharp.Image”类型转换为“ImageSharp.PixelFormats.Rgba32”?

To load the Image, I am using要加载图像,我正在使用

Image<Rgba32> image = Image.Load(path);

but I keep getting the error: Cannot implicitly convert type 'SixLabors.ImageSharp.Image' to 'SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32>'. An explicit conversion exists (are you missing a cast?).但我不断收到错误: Cannot implicitly convert type 'SixLabors.ImageSharp.Image' to 'SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32>'. An explicit conversion exists (are you missing a cast?). Cannot implicitly convert type 'SixLabors.ImageSharp.Image' to 'SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32>'. An explicit conversion exists (are you missing a cast?).

The API change in the latest release.最新版本中的 API 更改。 To explicitly get an Image<Rgba32> then call Image.Load<Rgba32>(path) instead.要显式获取Image<Rgba32>然后调用Image.Load<Rgba32>(path)代替。

However if you aren't working with low level raw pixel manipulation then you should probably just change your code instead to use the Image class directly as its a pixel type agnostic type that supports all the built in mutations without the added pixel type noise.但是,如果您不使用低级原始像素操作,那么您可能应该更改代码,而不是直接使用Image类作为其像素类型不可知类型,该类型支持所有内置突变,而不会增加像素类型噪声。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM