//package rt; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.beans.value.WritableValue; import javafx.event.EventHandler; import javafx.event.EventType; import javafx.geometry.Rectangle2D; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.stage.Stage; import javafx.util.Duration; public class RT_17041_ImageFragmentTest extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { BufferedImage bi = new BufferedImage(1024, 1024, BufferedImage.TYPE_INT_ARGB_PRE); DataBufferInt data = (DataBufferInt)bi.getRaster().getDataBuffer(); int [] iData = data.getData(); if (false) { for (int y = 0; y < 1024; y++) { for (int x = 0; x < 1024; x++) { iData[y*1024+x] = java.awt.Color.HSBtoRGB(x / 1024.0f, y / 2048.0f + 0.5f, 1.0f); } } } else { for (int y=0; y!=1024; ++y) { for (int x=0; x!=1024; ++x) { int t = x%3; iData[y*1024+x] = t*0x7f7f7f | 0xFF000000; // iData[y*1024+x] = (t * java.awt.Color.HSBtoRGB(x/1024.0f, 1.0f, 0.5f)) | 0xFF000000; } } } final ImageView imageView = new ImageView(Image.impl_fromExternalImage(bi)); imageView.setViewport(new Rectangle2D(256+15, 15, 300, 300)); imageView.setRotate(3.7); //startAnimation(imageView.xProperty(), 200, 300000); startAnimation(imageView.rotateProperty(), 360, 300000); //startAnimation(imageView.scaleXProperty(), 0.01, 3000); //startAnimation(imageView.scaleYProperty(), 0.01, 3000); Scene scene = new Scene(new Group(imageView), 300, 300); scene.addEventHandler(MouseEvent.MOUSE_DRAGGED, new EventHandler() { public void handle(MouseEvent event) { double sx = event.getX() / 100.0; double sy = event.getY() / 100.0; imageView.setScaleX(sx); imageView.setScaleY(sy); System.out.println("scaling to "+sx+" x "+sy); } }); stage.setScene(scene); stage.show(); } public void startAnimation(WritableValue target, T endValue, float millis) { Timeline timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); final KeyValue kv = new KeyValue(target, endValue); final KeyFrame kf = new KeyFrame(Duration.millis(millis), kv); timeline.getKeyFrames().add(kf); timeline.play(); } }