Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. import java.awt.*;
  2. class ChromaKey
  3. {
  4. public static void main(String[] args) //start of the main method
  5. {
  6. Picture pictureObj = new Picture("SecretMessage.png"); //creates a new Picture object representing the file in the parameter list
  7. pictureObj.explore(); //explore the Picture object which is currently the unaltered original image
  8. int redValue = 0; int greenValue = 0; int blueValue = 0; //declare and initialize the variables that hold the red, green, and blue values (0-255)
  9.  
  10. Pixel targetPixel = new Pixel(pictureObj, 0,0); //set the coordinate for the image origin
  11. Color pixelColor = null; //declare a Color object and set its initial value to null (or nothing)
  12.  
  13. for(int y=0; y < pictureObj.getHeight(); y++) //outside nested loop to traverse the image from top to bottom
  14. {
  15. for(int x = 0; x < pictureObj.getWidth(); x++) //inside nested loop to traverse the image from left to right
  16. {
  17. targetPixel = pictureObj.getPixel(x,y); //gets the x,y coordinate of the target pixel
  18. pixelColor = targetPixel.getColor(); //gets the color of the target pixel
  19.  
  20. redValue = pixelColor.getRed(); //assign the red component (0-255) of the target pixel to the redValue variable
  21. greenValue = pixelColor.getGreen(); //assign the green component (0-255) of the target pixel to the greenValue variable
  22. blueValue = pixelColor.getBlue(); //assign the blue component (0-255) of the target pixel to the blueValue variable
  23.  
  24. int redColor= 8;
  25. int greenColor= 0;
  26. int blueColor= 0;
  27.  
  28. int redColorReplace=255;
  29. int greenColorReplace=0;
  30. int blueColorReplace=0;
  31.  
  32. if(redValue==redColor && greenValue==greenColor && blueValue==blueColor)
  33. {
  34. redValue=redColorReplace;
  35. greenValue=greenColorReplace;
  36. blueValue=blueColorReplace;
  37. }
  38. pixelColor = new Color(redValue, greenValue, blueValue);//assign the color of the pixel
  39. targetPixel.setColor(pixelColor); //sets the new color of the target pixel
  40. }//end of the inner for loop
  41. }//end of the outer for loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement