10

How do I get the image format using SixLabors.ImageSharp?

In version 1.0.0-alpha9-00152 I could use:

Image<Rgba32> image = Image.Load(GetBytesFromBlobStorage());
IImageFormat format = image.CurrentImageFormat;

but .CurrentImageFormat() doesn't seen to be able in beta version 1.0.0-beta0001.

I want to know if the image is .png, .bmp or .jpeg.

James South
  • 10,147
  • 4
  • 59
  • 115
Andre Odendaal
  • 557
  • 6
  • 19

2 Answers2

21

Yeah, we moved your cheese a little bit with 1.0.0-beta0001.

The signature you are looking for is now.

public static Image<TPixel> Load<TPixel>(Stream stream, out IImageFormat format)
James South
  • 10,147
  • 4
  • 59
  • 115
2

If you only need to detect format without loading the whole image there is a method DetectFormatAsync:

public static Task<IImageFormat> DetectFormatAsync(Stream stream, CancellationToken cancellationToken = default)
Yuriy Gavrishov
  • 4,341
  • 2
  • 17
  • 29