다음과 같은 문제가 있습니다. 필기 입력 (손으로 직접 쓸 수 있음), 텍스트 삽입, 이미지 추가, pdf 등을 추가 할 수있는 빈 종이와 같은 프로그램을 작성합니다. ... 한 특정 기능에 대해 사용자가 창에 추가 한 노드를 이미지로 변환해야합니다. 다행히, 자바 FX-노드 좋은 방법 제공 :JavaFX TextArea 및 WebView의 스냅 샷 찍기
public void snapshot(...)
를하지만 한 가지 문제가 있습니다 : 나는 그들이 실패 텍스트 객체의 스냅 샷을 만들려고합니다. 스냅 샷을 찍을 수있는 유일한 노드는 javafx.scene.text.Text입니다. 다음 클래스 실패 : 여기
javafx.scene.control.TextArea
javafx.scene.web.WebView
내 문제를 설명하기 위해 예는 다음과 javafx.scene.text.Text - 객체를 생성하여 주위에 작업
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
TextArea textArea = new TextArea("Lorem Ipsum is simply dummy text"
+ " of the printing and typesetting industry. Lorem Ipsum has been \n"
+ "the industry's standard dummy text ever since the 1500s, when an \n"
+ "unknown printer took a galley of type and scrambled it to make a type\n"
+ " specimen book. It has survived not only five centuries, but also the\n"
+ " leap into electronic typesetting, remaining essentially unchanged. It\n"
+ " was popularised in the 1960s with the release of Letraset sheets containing\n"
+ " Lorem Ipsum passages, and more recently with desktop publishing software \n"
+ "like Aldus PageMaker including versions of Lorem Ipsum");
SnapshotParameters snapshotParameters = new SnapshotParameters();
snapshotParameters.setFill(Color.TRANSPARENT);
Image img = textArea.snapshot(snapshotParameters, null);
ImageView imgVw = new ImageView(img);
System.out.printf("img.width: %s height: %s%n", img.getWidth(), img.getHeight()); // <= width and height of the image img is 1:1! WHY?
Pane pane = new Pane();
pane.getChildren().addAll(imgVw);
Scene scene = new Scene(pane, 800,800);
pane.setMinWidth(800);
pane.setMinHeight(800);
pane.setMaxWidth(800);
pane.setMaxHeight(800);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
은 내가 생각할 수 및 그 사진을 찍어. 그러나 이것은 javafx.scene.web.WebView에 의해 표시되는 형식화 된 텍스트에 대해서는 실패합니다.
미리 도움 주셔서 감사합니다.
정말 고마워요! 완벽한 대답! – Soir