Load 1bpp PNG image and get the pixel data as byte array #1405
-
I have a 1bpp PNG image that I would like to load with ImageSharp, rotate it by 90 degrees and then get the pixel data of 1bpp image as byte array so it can be passed to another library which expects it like this. This is where I am stuck: byte[] DecodeImage(byte[] input1bppPng)
{
using (var image = Image.Load<???>(input1bppPng))
{
image.Mutate(x => x.Rotate(RotateMode.Rotate90));
return MemoryMarshal.AsBytes(image.GetPixelSpan()).ToArray();
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
JimBobSquarePants
Oct 27, 2020
Replies: 1 comment 5 replies
-
What's the actual memory layout of the buffer you require? Pngs don't actually store the information as 1bpp. A png encoded with a bit depth of 1 means 1 bit per sample or per palette index (not per pixel). Which means the color palette of the indexed png has a maximum of 2 palette entries. |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
mrapavy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's the actual memory layout of the buffer you require?
Pngs don't actually store the information as 1bpp. A png encoded with a bit depth of 1 means 1 bit per sample or per palette index (not per pixel). Which means the color palette of the indexed png has a maximum of 2 palette entries.