문제

I am writing a javaFx based POS system that will receive input via a touch screen monitor. The input screen will have lots of buttons (50+) with different image data on each button. I have been looking for a method to contain all these graphic images (small 75x75px) in one file that can be read at startup instead of opening 50 different image files. I imagine that this will speed up the start up process.

I have looked at java resource bundles as a method but it looks like this system is designed to store local specific content and it seems like it would be complex to implement for my needs.

I am wondering if anyone knows of some java or javaFx utilities or routines that would be suited to this problem. Maybe something where I could load all the image data, store it in some object, and then write this object out on one file. Maybe some sort of dictionary object that I could just write out to a file and then read back in on startup.

Thanks.

도움이 되었습니까?

해결책

@FXML
private Button btn1;

    Image img = new Image("/images/2013-07-14_14-40-17_89.jpg");

        ImageView iv = new ImageView();
        iv.setImage(img);
        Rectangle2D viewportRect = new Rectangle2D(100, 250, 50, 50);
        iv.setViewport(viewportRect);
        btn1.setGraphic(iv);

You can load one Image and create an ImageView (a Node) for every button. The ImageView picks a view port rectangle inside the large image.


To create a single file from several images, something like:

 BufferedImage totalImage = new BufferedImage(...);
 Graphics2D g = totalImage.createGraphics();
 String[] files = { ... };
 for (int i = 0; i < files.length; ++i) {
     BufferedImage img = ImageIO.read(files[i]);
     int x = i * 75;
     int y = 0;
     g.drawImage(x, y, img, ...);
 }
 ImageIO.write(totalImage, ...);
 g.dispose();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top