2018년 11월 1일 목요일

[JavaFx] ImageView Example


1. ImageView Example

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.File;

import javafx.scene.Node;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class FxImageView implements FxNode {

    ImageView imageView;
    String imageFile;

    public FxImageView() {
        imageView = new ImageView();
    }

    public FxImageView(String image) {
        imageFile = new File(image).toURI().toString();
        imageView = new ImageView(new Image(imageFile));
    }

    public FxImageView(int width, int height) {
        imageView = new ImageView();
        imageView.setPreserveRatio(true);
        imageView.setFitWidth(width);
        imageView.setFitHeight(height);
    }

    public FxImageView(String imageFile, int width, int height) {
        imageView = new ImageView(new Image(new File(imageFile).toURI().toString(), width, height, true, true));
        imageView.setPreserveRatio(true);
    }

    @Override public Node get() {
        return imageView;
    }

    public void load(String imageFile) {
        imageView.setImage(new Image(new File(imageFile).toURI().toString()));
    }
    
}

댓글 없음:

댓글 쓰기