How to replace colors in BufferedImage in JAVA

后端 未结 4 1864
星月不相逢
星月不相逢 2020-12-16 06:48

I\'m wondering if there is a more efficient method for replacing colors in a BufferedImage. At the moment I use the following method:

I fill an array with colors to

相关标签:
4条回答
  • 2020-12-16 07:01

    Instead of changing the value of the image pixels you can modify the underlying ColorModel. Much faster that way and no need to iterate over the whole image so it scales well.

    0 讨论(0)
  • 2020-12-16 07:12

    It looks like the idiomatic way to do this is to implement a LookupOp and then apply this operation to create a new target BufferedImage. There is a great answer here.

    0 讨论(0)
  • 2020-12-16 07:18

    Use a HashMap<Color,Color>. The key should be the original color, and the value the replacement. If the get returns null, do nothing.

    0 讨论(0)
  • 2020-12-16 07:27

    Have a look at BufferedImageFilter/BufferedImageOp to filter your image in the producer/consumer/observer paradigm.

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