0

While using java.awt.image.BufferedImage getSubimage() method BufferedImage outImage = bufferedImage.getSubimage(x, y, width, height); to get subimage, the color of subimage is wrong. enter image description here

How can i get the correct color image in java?

test image

P.S. after uploading the image to imgur and using the image downloaded from url, I found the color of subimage right...please use this image http://img01.taobaocdn.com/tfscom/LB17L9HKXXXXXbhXXXXSutbFXXX

0n1yDream
  • 112
  • 1
  • 9
  • You're saving the subimage as JPEG, but the subimage has a alpha channel... – MadProgrammer Oct 22 '15 at 03:48
  • I see the property of the source file, the property alpha channel is false... – 0n1yDream Oct 22 '15 at 03:51
  • Which is basically described [here](http://stackoverflow.com/questions/13072312/jpeg-image-color-gets-drastically-changed-after-just-imageio-read-and-imageio). The "basic" solution is to create a `BufferedImage` of `TYPE_RGB` and paint the subimage to it, then you can the new (non alpha based) image – MadProgrammer Oct 22 '15 at 03:51
  • I didn't say the "source", I said the "subimage". Save it as a PNG, see if you get the same problem. `ImageIO` doesn't support alpha channels in JPEGs :P – MadProgrammer Oct 22 '15 at 03:52
  • 1
    Can you provide a a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This is not a code dump, but an example of what you are doing which highlights the problem you are having. This will result in less confusion and better responses. I tried with your original image and have no issue – MadProgrammer Oct 22 '15 at 06:24
  • After i upload this source image and download it from imgur, the image is changed by imgur and have no issue... – 0n1yDream Oct 22 '15 at 06:32
  • http://img01.taobaocdn.com/tfscom/LB17L9HKXXXXXbhXXXXSutbFXXX @MadProgrammer you can use this image – 0n1yDream Oct 22 '15 at 08:16
  • Okay, I can at least read the image now :P - It might be a CMYK issue, see [this Q/A](http://stackoverflow.com/questions/2408613/unable-to-read-jpeg-image-using-imageio-readfile-file) for some more details. Most the solutions require some third party library/plugin, for [example](https://github.com/haraldk/TwelveMonkeys) – MadProgrammer Oct 22 '15 at 10:26

0 Answers0