Negative image

Report a typo

Image negatives have their colors inverted into complementary colors. Technically, for the 24-bit color mode, in order to create a negative, each pixel's color should be reversed in the following way:

Red = 255 - Red

Green = 255 - Green

Blue = 255 - Blue

The following code reads an image data into a BufferedImage instance and then inverts all pixels' color. Put the code lines in the correct order.

The "for loop" with the x variable precedes the "for loop" with the y variable.

Note that each click on the right arrow inserts 4 spaces for indentation.

Reorder lines using drag or arrows. Adjust indentation with left buttons
                }
              
                val colorNew = Color(255 - color.red, 255 - color.green , 255 - color.blue)
              
                for (y in 0 until myImage.height) {
              
                val myImage: BufferedImage = ImageIO.read(inputFile)
              
                myImage.setRGB(x, y, colorNew.rgb)
              
                val inputFile = File("imageIn.png")
              
                val color = Color(myImage.getRGB(x, y))
              
                for (x in 0 until myImage.width) {
              
                }
              
___

Create a free account to access the full topic