My batch jpg resizer works with color images, but grayscale ones become washed out

后端 未结 2 731
悲哀的现实
悲哀的现实 2021-01-16 05:23

I\'ve been having a problem with my Java program. It\'s for resizing images. You drop it into a folder and run it, and it creates a new folder with the resized images. It wo

相关标签:
2条回答
  • 2021-01-16 05:40

    In your code, you assume jpeg are encoded in RGB, but that's not always the case. It's also possible to encode 8 bit gray scaled jpeg. So I suggest that you try this when building your BufferedImage, replace :

    BufferedImage.TYPE_INT_RGB;
    

    by

    BufferedImage.TYPE_BYTE_GRAY;
    

    and see if it works for those images.

    If so, then you still have to find out a way to determine the encoding type to automatically change the type of BufferedImage color encoding to use, but you will be one stop closer.

    Regards, Stéphane

    0 讨论(0)
  • 2021-01-16 05:50

    If jdk's classes and methods are buggy, report the bug to oracle (oh! I wish I could go on saying to SUN..).

    And, while the next release will correct the bug ;), try some work arounds, scaling image by yourself like proposed here.

    Regards, Stéphane

    0 讨论(0)
提交回复
热议问题