本文整理汇总了Java中javafx.embed.swing.SwingFXUtils类的典型用法代码示例。如果您正苦于以下问题:Java SwingFXUtils类的具体用法?Java SwingFXUtils怎么用?Java SwingFXUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SwingFXUtils类属于javafx.embed.swing包,在下文中一共展示了SwingFXUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: take
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* Takes a snapshot of a canvas and saves it to the destination.
* <p>
* After the screenshot is taken it shows a dialogue to the user indicating the location of the snapshot.
*
* @param canvas a JavaFX {@link Canvas} object
* @return the destination of the screenshot
*/
public String take(final Canvas canvas) {
final WritableImage writableImage = new WritableImage((int) canvas.getWidth(), (int) canvas.getHeight());
final WritableImage snapshot = canvas.snapshot(new SnapshotParameters(), writableImage);
try {
ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), FILE_FORMAT, destination);
new InformationDialogue(
"Snapshot taken",
"You can find your snapshot here: " + destination.getAbsolutePath()
).show();
} catch (final IOException e) {
LOGGER.error("Snapshot could not be taken.", e);
new ErrorDialogue(e).show();
}
return destination.getAbsolutePath();
}
示例2: changed
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
@Override
public void changed(ObservableValue<? extends State> observable, State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
try {
//Determine the full url
String favIconFullURL = getHostName(webEngine.getLocation()) + "favicon.ico";
//System.out.println(favIconFullURL)
//Create HttpURLConnection
HttpURLConnection httpcon = (HttpURLConnection) new URL(favIconFullURL).openConnection();
httpcon.addRequestProperty("User-Agent", "Mozilla/5.0");
List<BufferedImage> image = ICODecoder.read(httpcon.getInputStream());
//Set the favicon
facIconImageView.setImage(SwingFXUtils.toFXImage(image.get(0), null));
} catch (Exception ex) {
//ex.printStackTrace()
facIconImageView.setImage(null);
}
}
}
示例3: call
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
@Override
protected Boolean call() throws Exception {
val fxTimeline = timeLine.getFxTimeline();
val totalFrames = toFrame(fxTimeline.getTotalDuration());
int frame = 0;
while (frame < totalFrames) {
updateProgress(frame, totalFrames);
updateMessage(String.format("%d / %d", frame + 1, totalFrames));
fxTimeline.jumpTo(toDuration(frame));
val image = newImage();
val latch = new CountDownLatch(1);
Platform.runLater(() -> {
scene.snapshot(image);
latch.countDown();
});
latch.await();
val file = new File(directory, String.format("frame_%05d.png", frame + 1));
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
frame++;
}
return Boolean.TRUE;
}
示例4: update
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* Receives an image from another node.
* @param image Input image
*/
@Override
public void update(Image image) {
imagePeer[ this.emptyPos++ % 2 ] = SwingFXUtils.fromFXImage(image,null);
if( getInputNumber() == INPUT_MAX ){
if (imagePeer[0] == null || imagePeer[1] == null )
System.out.println("Image NULL!");
String result = MSE(imagePeer[0], imagePeer[1]);
Graphics2D g2d;
BufferedImage bImg = new BufferedImage(80 , 60, BufferedImage.TYPE_INT_RGB);
g2d = bImg.createGraphics();
g2d.drawString(result,5 ,bImg.getHeight()/2);
setImage(SwingFXUtils.toFXImage(bImg,null));
System.out.printf("PSNR: %s\n",result);
super.update(getImage());
}
}
示例5: update
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* Whenever the input is changed or a new connection
* is made this function is called.
* @param image Current image
*/
@Override
public void update(Image image) {
imagePeer[ this.emptyPos++ % 2 ] = SwingFXUtils.fromFXImage(image,null);
if( getInputNumber() == INPUT_MAX ){
if (imagePeer[0] == null || imagePeer[1] == null )
System.out.println("Image NULL!");
int mtxResult [][] = minus(ImageUtil.convertToGreyTone(imagePeer[0]), ImageUtil.convertToGreyTone(imagePeer[1]));
setImage( ImageUtil.toImage( mtxResult ));
System.out.println("Sub!");
super.update(getImage());
}
}
示例6: minus
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* Method to do image subtraction between two images.
* @param A First image.
* @param B Second image.
* @return Returns the matrix representing the operation.
*/
private int[][] minus(int [][] A, int [][] B){
int n = A.length; /* A lines. */
int m = A[0].length; /* A columns. */
int o = B.length; /* B lines. */
int p = B[0].length; /* B columns. */
if(n != o || m != p)
return ImageUtil.convertToGreyTone(SwingFXUtils.fromFXImage(auxImg,null));
int [][] C = new int[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
C[i][j] = ImageUtil.normalize(Math.abs( A[i][j] - B[i][j] ) );
}
}
return C;
}
示例7: update
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* Receives an image from another node.
* @param image Input image
*/
@Override
public void update(Image image) {
imagePeer[ this.emptyPos++ % 2 ] = SwingFXUtils.fromFXImage(image,null);
if( getInputNumber() == INPUT_MAX ){
if (imagePeer[0] == null || imagePeer[1] == null )
System.out.println("Image NULL!");
int mtxResult [][] = and(ImageUtil.convertToGreyTone(imagePeer[0]), ImageUtil.convertToGreyTone(imagePeer[1]));
setImage( ImageUtil.toImage( mtxResult ));
System.out.println("AND!");
super.update(getImage());
}
}
示例8: and
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* AND two images.
* @param A First image.
* @param B Second image.
* @return Returns a matrix representing the operation.
*/
int[][] and(int [][] A, int [][] B){
int n = A.length; /* A lines. */
int m = A[0].length; /* A columns */
int o = B.length; /* B lines. */
int p = B[0].length; /* B columns. */
if(n != o || m != p)
return ImageUtil.convertToGreyTone(SwingFXUtils.fromFXImage(auxImg,null));
int [][] C = new int[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
C[i][j] = (byte) (A[i][j] & B[i][j]);
}
}
return C;
}
示例9: update
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* Receives an image from another node.
* @param image Input image
*/
@Override
public void update(Image image) {
imagePeer[ this.emptyPos++ % 2 ] = SwingFXUtils.fromFXImage(image,null);
if( getInputNumber() == INPUT_MAX ){
if (imagePeer[0] == null || imagePeer[1] == null )
System.out.println("Image NULL!");
int mtxResult [][] = or(ImageUtil.convertToGreyTone(imagePeer[0]), ImageUtil.convertToGreyTone(imagePeer[1]));
setImage( ImageUtil.toImage( mtxResult ));
System.out.println("OR!");
super.update(getImage());
}
}
示例10: or
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* OR two images.
* @param A First image.
* @param B Second image.
* @return Returns a matrix representing the operation.
*/
private int[][] or(int [][] A, int [][] B){
int n = A.length; /* A lines. */
int m = A[0].length; /* A columns. */
int o = B.length; /* B lines. */
int p = B[0].length; /* B columns. */
if(n != o || m != p)
return ImageUtil.convertToGreyTone(SwingFXUtils.fromFXImage(auxImg,null));
int [][] C = new int[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
C[i][j] = (byte) (A[i][j] | B[i][j]);
}
}
return C;
}
示例11: sum
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* Method to do image sum between two images.
* @param A First image.
* @param B Second image.
* @return Returns the matrix representing the operation.
*/
private int[][] sum(int [][] A, int [][] B){
int n = A.length; /* A lines. */
int m = A[0].length; /* A columns. */
int o = B.length; /* B lines. */
int p = B[0].length; /* B columns. */
if(n != o || m != p)
return ImageUtil.convertToGreyTone(SwingFXUtils.fromFXImage(auxImg,null));
int [][] C = new int[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
C[i][j] = ImageUtil.normalize(A[i][j] + B[i][j]);
}
}
return C;
}
示例12: update
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* Receives an image from another node.
* @param image Input image
*/
@Override
public void update(Image image) {
imagePeer[ this.emptyPos++ % 2 ] = SwingFXUtils.fromFXImage(image,null);
if( getInputNumber() == INPUT_MAX ){
if (imagePeer[0] == null || imagePeer[1] == null )
System.out.println("Image NULL!");
String result = PSNR(imagePeer[0], imagePeer[1]);
Graphics2D g2d;
BufferedImage bImg = new BufferedImage(80 , 60, BufferedImage.TYPE_INT_RGB);
g2d = bImg.createGraphics();
g2d.drawString(result+"",5 ,bImg.getHeight()/2);
setImage(SwingFXUtils.toFXImage(bImg,null));
System.out.printf("PSNR: %s\n",result);
super.update(getImage());
}
}
示例13: times
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
/**
* Method to do image multiplication between two images.
* @param A First image.
* @param B Second image.
* @return Returns the matrix representing the operation.
*/
private int[][] times(int [][] A, int [][] B){
int n = A.length; /* A lines. */
int m = A[0].length; /* A columns. */
int o = B.length; /* B lines. */
int p = B[0].length; /* B columns. */
if(n != o || m != p){
return ImageUtil.convertToGreyTone(SwingFXUtils.fromFXImage(auxImg,null));
}
int [][] C = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
C[i][j] = ImageUtil.normalize( A[i][j] * B[i][j] );
}
}
return C;
}
示例14: saveImageCache
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
public void saveImageCache() throws ImageCacheError
{
File dir = new File("cache/");
if (!dir.exists())
throw new ImageCacheError();
for (Map.Entry<Integer, Image> i : imageCache.entrySet())
{
BufferedImage bi = SwingFXUtils.fromFXImage(i.getValue(), null);
File file = new File("cache/" + i.getKey());
if (!file.exists() && bi != null)
{
try
{
ImageIO.write(bi, "png", file);
} catch (IOException e)
{
throw new ImageCacheError();
}
}
}
}
示例15: handleFileSaveAction
import javafx.embed.swing.SwingFXUtils; //导入依赖的package包/类
@FXML
private void handleFileSaveAction(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
File file = fileChooser.showSaveDialog(null);
if (file != null) {
try {
WritableImage writableImage = new WritableImage((int) drawingCanvas.getWidth(), (int) drawingCanvas.getHeight());
drawingCanvas.snapshot(null, writableImage);
RenderedImage renderedImage = SwingFXUtils.fromFXImage(writableImage, null);
ImageIO.write(renderedImage, "png", file);
} catch (IOException ex) {
Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}