Advertisement
MrPinzon

Untitled

May 19th, 2022
721
138 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.FileInputStream;
  2. import java.io.FileNotFoundException;
  3. import javafx.application.Application;
  4.  
  5. import javafx.scene.Group;
  6. import javafx.scene.Scene;
  7.  
  8. import javafx.scene.image.Image;
  9. import javafx.scene.image.ImageView;
  10. import javafx.scene.image.PixelReader;
  11. import javafx.scene.image.PixelWriter;
  12. import javafx.scene.image.WritableImage;
  13.  
  14. import javafx.scene.paint.Color;
  15. import javafx.stage.Stage;
  16.  
  17. public class widgets extends Application {
  18.     @Override
  19.     public void start(Stage stage) throws FileNotFoundException {
  20.         //Creating an image
  21.         Image image = new Image(new FileInputStream("/home/robot/IdeaProjects/UI_controls/src/main/java/com/example/ui_controls/HIS_logo.png"));
  22.         int width = (int)image.getWidth();
  23.         int height = (int)image.getHeight();
  24.  
  25.         //Creating a writable image
  26.         WritableImage wImage = new WritableImage(width, height);
  27.  
  28.         //Reading color from the loaded image
  29.         PixelReader pixelReader = image.getPixelReader();
  30.  
  31.         //getting the pixel writer
  32.         PixelWriter writer = wImage.getPixelWriter();
  33.  
  34.         //Reading the color of the image
  35.         for(int y = 0; y < height; y++) {
  36.             for(int x = 0; x < width; x++) {
  37.                 //Retrieving the color of the pixel of the loaded image
  38.                 Color color = pixelReader.getColor(x, y);
  39.  
  40.                 //Setting the color to the writable image
  41.                 if (x<y)
  42.                     writer.setColor(x, y, color.darker());
  43.                 else if (y > 200)
  44.                     writer.setColor(x, y, color.brighter());
  45.                 else
  46.                     writer.setColor(x, y, color.invert());
  47.             }
  48.         }
  49.         //Setting the view for the writable image
  50.         ImageView imageView = new ImageView(wImage);
  51.  
  52.         //Creating a Group object
  53.         Group root = new Group(imageView);
  54.  
  55.         //Creating a scene object
  56.         Scene scene = new Scene(root, 1150, 500);
  57.  
  58.         //Setting title to the Stage
  59.         stage.setTitle("Writing pixels ");
  60.  
  61.         //Adding scene to the stage
  62.         stage.setScene(scene);
  63.  
  64.         //Displaying the contents of the stage
  65.         stage.show();
  66.     }
  67.     public static void main(String args[]) {
  68.         launch(args);
  69.     }
  70. }
  71.  
Advertisement
RAW Paste Data Copied
Advertisement