Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import javafx.application.Application;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.image.PixelReader;
- import javafx.scene.image.PixelWriter;
- import javafx.scene.image.WritableImage;
- import javafx.scene.paint.Color;
- import javafx.stage.Stage;
- public class widgets extends Application {
- @Override
- public void start(Stage stage) throws FileNotFoundException {
- //Creating an image
- Image image = new Image(new FileInputStream("/home/robot/IdeaProjects/UI_controls/src/main/java/com/example/ui_controls/HIS_logo.png"));
- int width = (int)image.getWidth();
- int height = (int)image.getHeight();
- //Creating a writable image
- WritableImage wImage = new WritableImage(width, height);
- //Reading color from the loaded image
- PixelReader pixelReader = image.getPixelReader();
- //getting the pixel writer
- PixelWriter writer = wImage.getPixelWriter();
- //Reading the color of the image
- for(int y = 0; y < height; y++) {
- for(int x = 0; x < width; x++) {
- //Retrieving the color of the pixel of the loaded image
- Color color = pixelReader.getColor(x, y);
- //Setting the color to the writable image
- if (x<y)
- writer.setColor(x, y, color.darker());
- else if (y > 200)
- writer.setColor(x, y, color.brighter());
- else
- writer.setColor(x, y, color.invert());
- }
- }
- //Setting the view for the writable image
- ImageView imageView = new ImageView(wImage);
- //Creating a Group object
- Group root = new Group(imageView);
- //Creating a scene object
- Scene scene = new Scene(root, 1150, 500);
- //Setting title to the Stage
- stage.setTitle("Writing pixels ");
- //Adding scene to the stage
- stage.setScene(scene);
- //Displaying the contents of the stage
- stage.show();
- }
- public static void main(String args[]) {
- launch(args);
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement