Closed salamanders closed 2 years ago
I think there's two things at issue here -- 1) what is the best way to create greyscale images? and 2) what exactly does imageType()
do?
First, I'll answer the easy of the two, which is (2) what does imageType()
do -- that actually is the image type (how the pixel data is represented) of BufferedImage
that is used behind the scenes for drawing the resulting thumbnail. This is something the API documentation doesn't mention explicitly since it's a implementation detail, but probably wouldn't hurt to include. What exact effects this would have is a different question, however. It's highly dependent on what the drawing operations that Java provides will do upon drawing "color" images on such a greyscale-configured BufferedImage
.
Second, (1) what is the best way to create greyscale images, actually needs a little more information -- are you trying to end up with an image that is only in shades of gray, but also has support for color and transparency? Or, are you trying to get an image with the format that represents each pixel in a shades of gray manner?
2: Great!
1: Good q, I want a "real" grayscale image - pixels in shades of gray, less memory needs, ready to be stuffed into a ML bitmap intake that is expecting grayscale. This one. https://commons.wikimedia.org/wiki/File:Grayscale_8bits_palette_sample_image.png
1: Good q, I want a "real" grayscale image - pixels in shades of gray, less memory needs, ready to be stuffed into a ML bitmap intake that is expecting grayscale. This one. https://commons.wikimedia.org/wiki/File:Grayscale_8bits_palette_sample_image.png
In that case, probably using BufferedImage.TYPE_BYTE_GRAY
would work. As I mentioned in the paragraph about (2), using the imageType
tells Thumbnailator to use that BufferedImage
type to draw the resulting thumbnail to, so my guess is that it would work fine. I suggest you actually try it out with some sample images and verify that it does work to your expectation.
Closing for no activity.
Expected behavior
I was wondering if imageType(BufferedImage.TYPE_BYTE_GRAY) actually converts the image to grayscale? The API https://coobird.github.io/thumbnailator/javadoc/0.4.8/net/coobird/thumbnailator/Thumbnails.Builder.html#imageType(int) doesn't actually say.
Ideally it would convert to grayscale (or other type) if necessary, and be a no-op if it was already the desired type.