Topic 1 - Variables and Data Types
Topic 2 - Conditionals and Strings
Topic 3 - Loops
Topic 4 - Arrays
Topic 5 - File Handling
Semester 1 Projects
Topic 6 - Classes/Objects and Methods
Topic 7 - ArrayLists
Semester Projects

Part 1e: Green Screen

Green Screen implements an operation that is used frequently in movies to merge actors into a background scene. The technique uses a particular range of colors (such as green) to represent a background that can later be made transparent via software. The most common colors are green and blue (which give rise to the more specific names green screen and blue screen) because those colors are most easily differentiated from flesh tones. 

Your task in this method is to create a new image whose pixels are the same as those of the source image, but with any green pixels converted to transparent ones (the image above at right has a transparent background). Since the green pixels in an image will rarely be precisely equal to Java’s Color.GREEN, you should treat a pixel as green if its green component is at least twice as large as the maximum of its red and blue component. The Math.max method may come in handy here; it takes 2 numbers as parameters and returns the larger one: 

int bigger = Math.max(23, 42);  // returns 42

To create a transparent pixel, you need to specify a fourth value stored inside a pixel (alongside its RGB values), called the alpha value (between 0 and 255). An alpha of 0 means the pixel is completely transparent and will show whatever is beneath it. An alpha of 255 (the default) means the pixel is completely opaque and will show just the RGB color it stores. Values in between are partially transparent. Luckily, GImage.createRGBPixel lets you optionally specify the alpha as a 4th parameter: 

int transparentPixel = GImage.createRGBPixel(1, 1, 1, 0);
int opaquePixel = GImage.createRGBPixel(1, 1, 1);

Once an image has been “green-screened”, you can overlay it on top of another image. For example, we can take our Rey-after-GreenScreen.png image and put it on top of MilleniumFalcon.png to look like this: 

To do this, first run the Green Screen algorithm on an image, and save it to a file. Then, load in the background image you would like to use, and click “Overlay Image” to overlay another image on top. Select a previously-saved green-screened image, and it will be added on top.