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

Image color changed after image resizing #119

Open
jpazardzievska opened this issue Nov 18, 2016 · 3 comments
Open

Image color changed after image resizing #119

jpazardzievska opened this issue Nov 18, 2016 · 3 comments

Comments

@jpazardzievska
Copy link

jpazardzievska commented Nov 18, 2016

I am using Scalr to resize images. I have a problem when trying to resize one image. Scalr is changing the color of the resized image (adds red color). The image that I try to resize is in jpg format.

In short, this is the outline of my code.
I read the file from byte array:
BufferedImage image = ImageIO.read(bis);

Then I resize the image using imgscalr:

Scalr.resize(image, Scalr.Method.ULTRA_QUALITY, Scalr.Mode.AUTOMATIC, targetWidth, targetHeight);

Then, I write it to output file:

ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, extension, baos);

The type of the image before and after resizing is same and equals to TYPE_4BYTE_ABGR.

I tried to use this solution #82 by removing the alpha channel before resizing the image, but no luck, the image then turned to black after resizing.

When writing to output file I use the extension of the image to find the right ImageWriter.
I found that using PNGImageWriter is solving the issue. But, is it good solution to use PNGImageWriter to write jpg, jpeg images?

Can you please explain me?

Thank you

@slorber
Copy link

slorber commented Mar 8, 2017

I have the same problem (but with input images of type 2 or 6 bellow, both for JPG/PNG). Both images have in common support for alpha but do not include any transparent background.

2

bulb

Any idea?

@mfirry
Copy link

mfirry commented Feb 13, 2019

Any fix to this?

@Sodacooky
Copy link

according to other issue, it might be happen on coverting ARGB(RGBA?) image and the library process only first 3 color byte.
i use the method described in https://stackoverflow.com/questions/44182400/how-to-convert-bufferedimage-rgba-to-bufferedimage-rgb to convert the image into RGB format and work well.

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

4 participants