Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create new instance of Image in C# using SixLabors.ImageSharp

I am trying to create new instance of Image class with SixLabors.Imagesharp but I got error. The system I work with used the old ImageSharp and We want to renew nuget packages and use SixLabors.ImageSharp instead.

The code used to be like this: OLD Code with ImageSharp:

var resultImage = new Image<Rgba32>(outputImageWidth, outputImageHeight);

The new code I try to write with SixLabors.ImageSharp is exactly the same but this time I got the massage:

Severity Code Description   Project File Linem Suppression State
Error CS0315 The type 'SixLabors.ImageSharp.PixelFormats.Rgba32' cannot be used as type parameter 'TPixel' in the generic type or method 'Image<TPixel>'. There is no boxing conversion from 'SixLabors.ImageSharp.PixelFormats.Rgba32' to '?'.

I tried a lot of other ways to create a new Image but I failed. Do you have any idea how I can create new Image using SixLabors.Imagesharp?

like image 479
Parham Gitijah Avatar asked Oct 26 '25 08:10

Parham Gitijah


1 Answers

The namespace for the pixel format has changed so your code is missing an import.

using SixLabors.ImageSharp.PixelFormats;

The following code compiles and runs for 1.0.0-rc0001

using (var image = new Image<Rgba32>(1000, 1000))
{
    // Do something
}

Documentation

like image 150
James South Avatar answered Oct 28 '25 21:10

James South



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!