Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes on indexed images. #18

Open
chico-ubuntu opened this issue Apr 30, 2024 · 0 comments
Open

Crashes on indexed images. #18

chico-ubuntu opened this issue Apr 30, 2024 · 0 comments

Comments

@chico-ubuntu
Copy link

chico-ubuntu commented Apr 30, 2024

It crashes on indexed images. I believe the issue lies here in Encode(Bitmap b, float quality, out IntPtr result, out long length)
using (Bitmap b2 = b.Clone(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
Encode(b2, quality, out result, out length);
}
I've created a workaround that works nicely which is
if (b.PixelFormat.HasFlag(PixelFormat.Indexed))
{
using (var bitmap = new Bitmap(b.Width, b.Height, PixelFormat.Format32bppArgb))
{
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.DrawImageUnscaled(b, 0, 0, b.Width, b.Height);
}
//this is using the stream to. it would have to be revised to reflect your out params
Encode(bitmap, to, quality);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant