Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?).

like image 806
Tiarnan Avatar asked Sep 04 '19 13:09

Tiarnan


People also ask

How to get RGBA32 image from a path?

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

How to copy the pixel data of an image<bgra32>?

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:

What is the best way to convert an image to bitmap?

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!)

Is there a way to convert raw pixels to bytes?

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.


Video Answer


1 Answers

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.

like image 89
tocsoft Avatar answered Oct 16 '22 21:10

tocsoft