2016-12-05 5 views
0

enter image description here Xを画像をロードし、ユーザーがそれをクリックすることを可能にして取得することができます私のJavaFXアプリケーションY座標が印刷されます。JavaFXのXとY軸の中心を取得する方法 - ポイント[0,0]画像の中心になるようにし

問題は、画像の左上隅を中心とXとYを設定する方法の任意の考え、代わりに実際の画像の画像の「中心」[0,0]であることがありますか?ここ

は、イメージをロードするためのコードである:ここ

BufferedImage bufferedImage = ImageIO.read(file); 
Image image = SwingFXUtils.toFXImage(bufferedImage, null); 
myImageView.setImage(image); 
myImageView.setFitWidth(300); 
myImageView.setPreserveRatio(true); 
myImageView.setCache(true); 

はmouseClickedEventの位置を印刷するためのコードである:

myImageView.setOnMouseClicked(ev -> { 
    System.out.println("[" + ev.getX() + ", " + ev.getY() + "]"); 
}); 

レッドrectablge実際[0,0] あります実際の中心とEXPEの間のオフセットを算出することにより :ブルーrectabgleが期待[0,0]

答えて

1

は答えを発見されましたCTEDセンターは、私が実際にXを得ることができたとY座標:

  double x = event.getX() - imageWidth/2; 
      double y = (event.getY() * -1) + (imageLength/2); 
      String msg ="[" + decimalFormat.format(x) + "," + decimalFormat.format(y) +"]"; 
関連する問題