Sunday, June 19, 2016

47. BoxBlur

A BoxBlur applies low-pass filtering to an image, representing the node.


It just averages the values of pixels in a range.


package ex47;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.effect.BoxBlur;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Ex47 extends Application {
    
    @Override
    public void start(Stage stage) {
        VBox root = new VBox(50);
        root.setAlignment(Pos.CENTER);
        
        BoxBlur boxBlur1 = new BoxBlur();
        boxBlur1.setWidth(5);
        boxBlur1.setHeight(5);
        
        Text text1 = new Text("blur1 (5,5)");
        text1.setFont(Font.font("Georgia", FontWeight.BOLD, 32));
        text1.setFill(Color.GREEN);
        text1.setEffect(boxBlur1);
        
        BoxBlur boxBlur2 = new BoxBlur();
        boxBlur2.setWidth(2);
        boxBlur2.setHeight(2);
        
        Text text2 = new Text("blur2 (2,2)");
        text2.setFont(Font.font("Georgia", FontWeight.BOLD, 32));
        text2.setFill(Color.GREEN);
        text2.setEffect(boxBlur2);
        
        root.getChildren().addAll(text1, text2);
        Scene scene = new Scene(root, 500, 200, Color.YELLOW);
        stage.setTitle("Example 47. BoxBlur");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}

This is the output:


No comments:

Post a Comment