How to Flip Pixels in Java With Getpixel

The Java "setPixel" and "getPixel" functions let you flip pixels within an image. You can also use the functions to change pixels for an image you create using the Java programming language. These two functions help you manipulate images, so you can automate image functions for users and display the results on a Web page or on a desktop form.

Instructions

    • 1

      Open the Java editor, and open the project and source code file you want to edit. Choose the source code file you want to use to display the image.

    • 2

      Open the image file you want to edit. The following code opens the image file you want to use to set up the pixel swap:

      img= new ProcessBuilder("mspaint","image.jpg");

      Replace "image.jpg" with your own image file. You can use a JPG, GIF or a PNG file.

    • 3

      Retrieve a pixel from the image. The following code gets the first pixel for the image:

      pixel1 = getPixel(0, 0, img);

    • 4

      Swap the pixel with a new pixel and save it to the image. The following code changes the pixel in the image with the next image in the file:

      img.setPixel(img, 1, 1);

Related Searches

References

Related Ads

Check It Out

7 Tips for Photographing Your Kids on Halloween