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
?
Asked
Active
Viewed 1,657 times
9

Konrad Kokosa
- 16,563
- 2
- 36
- 58

Chris
- 1,101
- 8
- 13
-
I'm curious as to why this question was closed. I understand it and can provide an answer. – James South Nov 12 '20 at 16:11
-
1@JamesSouth People confusing "I don't understand this question" with "this question is unclear" is an unfortunately common problem here, and one that has only gotten worse since the number of close votes was reduced. – StackOverthrow Nov 12 '20 at 16:39
-
Very disappointing to see. – James South Nov 12 '20 at 16:50
1 Answers
7
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.

huysentruitw
- 27,376
- 9
- 90
- 133

James South
- 10,147
- 4
- 59
- 115