Skip to content

Image color loss during conversion #201

@aleksanderFox

Description

@aleksanderFox

Expected behavior

Please describe what you are expecting the library to perform.
The image does not lose color during conversion.

Actual behavior

Hello!
I'm using the thumbnailator library to compress and convert customers images to png (to default size 200x200).
One user came in with an image that was losing color (black gets lighter).
Perhaps the error is due to the fact that the original image was 16 BitsPerPixel - the result is 32 BitsPerPixel.
Perhaps I'm not using the library correctly.
Help me to understand.

Steps to reproduce the behavior

My code:

    public static final Blob convertResizeImage(BufferedImage image, String formatName/*PNG*/, int targetWidth/*200*/, int targetHeight/*200*/) throws SQLException, IOException, InstantiationException, IllegalAccessException {
        int imgType = image.getType();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        Thumbnails.of(image)
                .size(targetWidth, targetHeight)
                .outputFormat(formatName)
                .imageType(imgType)
                .outputQuality(1)
                .toOutputStream(outputStream);
        byte[] data = outputStream.toByteArray();
        return bytes2Blob(data);
    }

Source image:
source

Converted image:
destination

Environment

  • OS vendor and version: Windows 10
  • JDK vendor and version: Corretto 1.8
  • Thumbnailator version: 0.4.18

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions