Skip to content

Crashes on indexed images. #18

@chico-ubuntu

Description

@chico-ubuntu

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);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions