Search code examples
c#opentkrgbaimagesharp

Convert ImageSharp.Image to ImageSharp.PixelFormats.Rgba32?


I am following a tutorial (https://opentk.net/learn/chapter1/4-textures.html) using ImageSharp. How do I convert the type 'ImageSharp.Image' to '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?).


Solution

  • The API change in the latest release. To explicitly get an Image<Rgba32> then call Image.Load<Rgba32>(path) instead.

    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.