简体   繁体   中英

Using ImageSharp what's the best way to convert incoming buffer containing Bgra32 to an ImageSharp Image<Rgba24> image?

I get PixelFormats.Bgra32 images from UAP and WPF and I would like to know the fastest way to convert them to and from SixLabors.ImageSharp Image<Rgba32> images. Is there some magic "mutate" that can flip the pixel bytes after I've copied the buffer using TryGetSinglePixelSpan ?

There's no shortcut for mutating an existing image but you can create a new one with the pixel format you need from the first.

Image<Rgba32> rgba;

// Load decodes
// LoadPixelData copies
// WrapMemory wraps
using (Image<Bgra32> bgra = Image.LoadPixelData<Bgra32>(...))
{
   rgba = bgra.CloneAs<Rgba32>(bgra.GetConfiguration());
}

You can then do whatever you need with the Rgba32 image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM