SwingFXUtils.fromFXImag方法没有返回 - 并且似乎处于某种死锁状态 - 执行没有停止并且没有抛出异常。
下面是代码:
package test;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Button;
import javafx.scene.image.WritableImage;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
public class Test extends javafx.application.Application {
static FileOutputStream fos;
static BufferedImage bi;
static WritableImage wi;
@Override
public void start(Stage primaryStage) throws Exception {
try{
WritableImage wi=new WritableImage(500,500);
}catch(Exception e){;}
Button button2 = new Button("Accept");
wi = new WritableImage(500,500);
wi = button2.snapshot(new SnapshotParameters(), null);
bi = new BufferedImage(500,500,BufferedImage.TYPE_INT_ARGB);
bi= (BufferedImage)SwingFXUtils.fromFXImage(wi, null);
}
public static void main(String [] args){
try{
File file = new File("c:\test.png");
file.createNewFile();
file.setReadable(true);
fos=new FileOutputStream(file);
ImageIO.write(bi, "PNG", fos);
}
catch(IOException e){}
}
}
在调试器中,我在程序的所有行上放置了一个断点。它暂停: bi =(BufferedImage)SwingFXUtils.fromFXImage(wi,null); 并且不会继续 - 尽管程序仍处于运行状态。
程序没有输出或错误。