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?).
The API change in the latest release. To explicitly get an Image<Rgba32> then call Image.Load<Rgba32> (path) instead.
The pixel data of an Image<Bgra32> can be directly copied to a Bitmap of PixelFormat.Format32bppArgb. (The difference between the component order is not a typo!) In that case both workBuffer and the following call is becomes unnecessary:
The pixel data of an Image<Bgra32> can be directly copied to a Bitmap of PixelFormat.Format32bppArgb. (The difference between the component order is not a typo!)
Onto the second question: There's a transformation API function called AutoOrient (). Look it up ;) If you are looking to convert the raw pixels into a byte [] you do the following. If you are looking to convert the encoded stream as a byte [] (which I suspect is what you are looking for). You do this.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With