My goal is to swap the red and blue channels of a java
Is there any way to achieve this other than inefficiently iterating over each pixel value und swapping the channels? I was thinking of some bitwise magic or some integrated function I don't know of.
Any help is appreciated.
Maybe you create an new instance of
BufferedImage with the same
WritableRaster raster and the same properties, but with a ColorModel with the colors swaped:
ColorModel swappedColorModel = new DirectColorModel(24, 0x000000ff, // Red -> Blue 0x0000ff00, // Green 0x00ff0000, // Blue -> Red 0x0 // Alpha ); BufferedImage swapedColorImage = new BufferedImage (swappedColorModel, originalImage.getRaster(), swappedColorModel.isAlphaPremultiplied(), properties);
I didn't tried this code