Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- class ChromaKey
- {
- public static void main(String[] args) //start of the main method
- {
- Picture pictureObj = new Picture("SecretMessage.png"); //creates a new Picture object representing the file in the parameter list
- pictureObj.explore(); //explore the Picture object which is currently the unaltered original image
- int redValue = 0; int greenValue = 0; int blueValue = 0; //declare and initialize the variables that hold the red, green, and blue values (0-255)
- Pixel targetPixel = new Pixel(pictureObj, 0,0); //set the coordinate for the image origin
- Color pixelColor = null; //declare a Color object and set its initial value to null (or nothing)
- for(int y=0; y < pictureObj.getHeight(); y++) //outside nested loop to traverse the image from top to bottom
- {
- for(int x = 0; x < pictureObj.getWidth(); x++) //inside nested loop to traverse the image from left to right
- {
- targetPixel = pictureObj.getPixel(x,y); //gets the x,y coordinate of the target pixel
- pixelColor = targetPixel.getColor(); //gets the color of the target pixel
- redValue = pixelColor.getRed(); //assign the red component (0-255) of the target pixel to the redValue variable
- greenValue = pixelColor.getGreen(); //assign the green component (0-255) of the target pixel to the greenValue variable
- blueValue = pixelColor.getBlue(); //assign the blue component (0-255) of the target pixel to the blueValue variable
- int redColor= 8;
- int greenColor= 0;
- int blueColor= 0;
- int redColorReplace=255;
- int greenColorReplace=0;
- int blueColorReplace=0;
- if(redValue==redColor && greenValue==greenColor && blueValue==blueColor)
- {
- redValue=redColorReplace;
- greenValue=greenColorReplace;
- blueValue=blueColorReplace;
- }
- pixelColor = new Color(redValue, greenValue, blueValue);//assign the color of the pixel
- targetPixel.setColor(pixelColor); //sets the new color of the target pixel
- }//end of the inner for loop
- }//end of the outer for loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement