Skip to content

Saving Gray8 image as jpeg results in 24 bit image #807

@CoenraadS

Description

@CoenraadS

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

I found this:
#672 (comment)

@jherby2k in our current design Image does not preserve the bit rate / color model of the original encoded data.

And this:

https://stackoverflow.com/questions/52407878/load-and-save-opaque-8-bit-png-files-using-imagesharp

Note. The png encoder by default will save the image in the input color type and bit depth. If you want to encode the image in a different color type you will need to new up an PngEncoder instance with the ColorType and BitDepth properties set.

Description

I am loading/resize an 8 bit png, however I want to save as .jpg

JpegEncoder does not have ColorType or BitDepth

Steps to Reproduce

Input Image:
201812211019388645_validpos_19 19875_21 285_439_12

private static void resizeUsingImageSharp(byte[] bytes, MemoryStream output)
        {
            var encoder = new JpegEncoder();
            encoder.Quality = 10;

            var decoder = new PngDecoder();
            decoder.IgnoreMetadata = true;

            var image = Image.Load<Gray8>(bytes, decoder);

            image.Mutate(ctx => ctx.Resize(96, 96));
            // Using .Grayscale() makes no difference, still saves 24 bit image

            // encoder.Encode<Gray8>(image, output); also doesn't work

            image.SaveAsJpeg(output, encoder);
        }

Output Image:
imagesharp

System Configuration

  • ImageSharp version:
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-dev002321" />
<PackageReference Include="SkiaSharp" Version="1.68.0" />
  • Environment (Operating system, version and so on):
    Window 10
  • .NET Framework version:
    netcoreapp3.0
  • Additional information:

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