Thursday, December 20, 2012

JavaFX example, get PixelReader for Image

Interface javafx.scene.image.PixelReader defines methods for retrieving the pixel data from an Image or other surface containing pixels. To get PixelReader, call getPixelReader() method of the associated Image object.

package testjavafx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelReader;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class TestJavaFX extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        
        Text text = new Text();
        
        Image image = new Image("http://goo.gl/kYEQl");
        ImageView imageView = new ImageView();
        imageView.setImage(image);
        
        PixelReader pixelReader = image.getPixelReader();
        text.setText("PixelFormat: " + pixelReader.getPixelFormat());
        
        VBox vBox = new VBox();
        vBox.getChildren().addAll(imageView, text);

        StackPane root = new StackPane();
        root.getChildren().add(vBox);
        Scene scene = new Scene(root, 500, 300);
        primaryStage.setTitle("java-buddy.blogspot.com");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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


JavaFX example, get PixelReader for Image
JavaFX example, get PixelReader for Image


No comments:

Post a Comment