Код: Выделить всё
public class TestFx extends Application {
@Override
public void start(Stage primaryStage) {
WritableImage image = createColoredImage();
ImageView imageView = new ImageView(image);
imageView.setOnDragDetected(event -> {
Dragboard db = imageView.startDragAndDrop(TransferMode.COPY);
db.setDragView(image);
ClipboardContent content = new ClipboardContent();
content.putImage(image);
db.setContent(content);
event.consume();
});
VBox root = new VBox(20, imageView);
primaryStage.setScene(new Scene(root, 1000, 250));
primaryStage.setTitle("Dragboard Image Width Test");
primaryStage.show();
}
private WritableImage createColoredImage() {
int width = 800;
int height = 100;
WritableImage image = new WritableImage(width, height);
PixelWriter writer = image.getPixelWriter();
int segmentWidth = 100;
for (int x = 0; x < width; x++) {
Color color = (x / segmentWidth) % 2 == 0 ? Color.GREEN: Color.RED;
for (int y = 0; y < height; y++) {
writer.setColor(x, y, color);
}
}
return image;
}
public static void main(String[] args) {
launch(args);
}
}
Может объяснить, как предотвратить это сокращение? Можно ли рассчитать полученные размеры изображения? Например, каким будет конечный размер изображения, если исходные размеры ширины × высота?
Подробнее здесь: https://stackoverflow.com/questions/796 ... l-its-size