public class ImageExample extends Application
1: import javafx.application.Application;
2: import javafx.scene.canvas.Canvas;
3: import javafx.scene.Scene;
4: import javafx.scene.Group;
5: import javafx.stage.Stage;
6: import javafx.scene.canvas.GraphicsContext;
7: import javafx.scene.shape.ArcType;
8: import javafx.scene.paint.Color;
9: import javafx.scene.image.Image;
10: import javafx.scene.effect.Reflection;
11:
12: public class ImageExample extends Application
13: {
14: public static void main(String[] args)
15: {
16: launch(args);
17: }
18:
19: @Override
20: public void start(Stage primaryStage) throws Exception
21: {
22: Group root = new Group();
23: Scene scene = new Scene(root);
24:
25: // Java looks for "java.jpg" in the default folder
26: Image img = new Image("java.jpg");
27: Canvas canvas = new Canvas(400, 400);
28: GraphicsContext gc = canvas.getGraphicsContext2D();
29: // Draw image in normal scaling at (1,1)
30: gc.drawImage(img, 1, 1);
31: // Draw image twice as large to the right of
32: // previous image
33: gc.drawImage(img, img.getWidth() + 10, 1,
34: img.getWidth() * 2, img.getHeight() * 2);
35: // Draw image below the first with a reflection effect
36: gc.setEffect(new Reflection());
37: gc.drawImage(img, 1, img.getHeight() *2);
38:
39: root.getChildren().add(canvas);
40: primaryStage.setTitle("Drawing Images in JavaFX");
41: primaryStage.setScene(scene);
42: primaryStage.show();
43: }
44: }