Java-Image-Prozessor
Main.java
public final class Main extends javafx.application.Application
{
@java.lang.Override
public void start( final javafx.stage.Stage stage )
{
stage.setTitle( "Image Viewer" );
stage.setWidth( 1 );
stage.setHeight( 1 );
final javafx.scene.layout.VBox box = new javafx.scene.layout.VBox();
{ final javafx.scene.image.ImageView view = new javafx.scene.image.ImageView();
{ final java.io.InputStream stream = Main.class.getResourceAsStream
( /* must be in the SAME DIRECTORY as the class file! */ "example.jpg" );final javafx.scene.image.Image image = new javafx.scene.image.Image( stream );
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
final javafx.scene.image.WritableImage writable
= new javafx.scene.image.WritableImage( ( int )image.getWidth(), ( int )image.getHeight() );final javafx.scene.image.PixelWriter writer = writable.getPixelWriter();
/* Obtain PixelReader */
final javafx.scene.image.PixelReader reader = image.getPixelReader();
System.out.println("Image Width: "+image.getWidth());
System.out.println("Image Height: "+image.getHeight());
System.out.println("Pixel Format: "+reader.getPixelFormat());for ( int y = 0; y < image.getHeight(); ++y )
{for (int x = 0; x < image.getWidth(); ++x)
{final javafx.scene.paint.Color color = reader.getColor( x, y );
/* color.toString()
getRed()getGreen()getBlue()
getOpacity()getSaturation()getHue()getBrightness(); *//* if( color.getSaturation() > 0.2 && color.getHue() > 180 && color.getHue() < 300 ) */
/* if
( color.getSaturation() > 0.2 &&
color.getHue() > 50 &&
color.getHue() < 310 )
writer.setColor
( x, y,
javafx.scene.paint.Color.hsb
( color.getHue() + 190,
color.getSaturation() * color.getSaturation(),
color.getBrightness(), color.getOpacity() )); *//* if
( color.getBrightness() > 0.2 &&
color.getSaturation() > 0.4 &&
color.getHue() > 50 &&
color.getHue() < 310 )
writer.setColor
( x, y,
javafx.scene.paint.Color.hsb
( color.getHue() + 190,
java.lang.Math.sqrt( color.getSaturation() ),
java.lang.Math.pow( color.getBrightness(), 1.5 ), color.getOpacity() )); */if
( color.getBrightness() < 0.5 &&
( color.getRed() * 2 < color.getBlue() &&
color.getRed() * 2 < color.getGreen() ))writer.setColor
( x, y,
javafx.scene.paint.Color.color
( color.getRed(), ( color.getGreen() / 2 ), ( color.getBlue() / 2 ), color.getOpacity() ));else writer.setColor( x, y, color );
}
}
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
view.setImage( writable );
view.setPreserveRatio( true );
view.fitWidthProperty().bind( stage.widthProperty() );
view.fitHeightProperty().bind( stage.heightProperty() ); }
box.getChildren().addAll( view ); }
stage.setScene( new javafx.scene.Scene( box ) );
{ /* set stage size to screen size */
final javafx.geometry.Rectangle2D bounds = javafx.stage.Screen.getPrimary().getVisualBounds();
stage.setX( bounds.getMinX() );
stage.setY( bounds.getMinY() );
stage.setWidth( bounds.getWidth() );
stage.setHeight( bounds.getHeight() ); }
stage.show(); }
public static void main( final java.lang.String[] args )
{ Main.launch( args ); }}