當前位置: 首頁>>代碼示例>>Java>>正文


Java SwingFXUtils.toFXImage方法代碼示例

本文整理匯總了Java中javafx.embed.swing.SwingFXUtils.toFXImage方法的典型用法代碼示例。如果您正苦於以下問題:Java SwingFXUtils.toFXImage方法的具體用法?Java SwingFXUtils.toFXImage怎麽用?Java SwingFXUtils.toFXImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.embed.swing.SwingFXUtils的用法示例。


在下文中一共展示了SwingFXUtils.toFXImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildData

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
public void buildData() throws SQLException, IOException {
	data = FXCollections.observableArrayList();
	c = database.SqliteConnection.getConnection();
	String SQL = "SELECT * from Employee";
	ResultSet rs = c.createStatement().executeQuery(SQL);

	while (rs.next()) {
		byte[] imageInbyte = rs.getBytes(9);
		BufferedImage img1 = ImageIO.read(new ByteArrayInputStream(imageInbyte));
		Image image = SwingFXUtils.toFXImage(img1, null);
		EmployeeClass ec = new EmployeeClass(rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5),
				rs.getString(6), rs.getString(7), rs.getString(8), new ImageView(image));
		data.add(ec);
	}
	c.close();

	wrapText();
	table.setItems(data);
}
 
開發者ID:djdivix,項目名稱:IDBuilderFX,代碼行數:20,代碼來源:ViewMuliParsedController.java

示例2: viewSingle

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
public void viewSingle() throws SQLException, IOException {
	Connection c;
	c = database.SqliteConnection.getConnection();
	String SQL = "SELECT * from Employee";
	ResultSet rs = c.createStatement().executeQuery(SQL);
	while (rs.next()) {
		namelbl.setText(rs.getString(2));
		emaillbl.setText(rs.getString(3));
		moblbl.setText(rs.getString(4));
		addlbl.setText(rs.getString(5));
		addlbl.setWrapText(true);
		doblbl.setText(rs.getString(6));
		sexlbl.setText(rs.getString(7));
		fnamelbl.setText(rs.getString(8));
		byte[] imageInbyte = rs.getBytes(9);
		BufferedImage img1 = ImageIO.read(new ByteArrayInputStream(imageInbyte));
		Image image = SwingFXUtils.toFXImage(img1, null);
		photo.setImage(image);
		photo.setPreserveRatio(true);
	}
	c.close();
}
 
開發者ID:djdivix,項目名稱:IDBuilderFX,代碼行數:23,代碼來源:ViewSingleParsedController.java

示例3: retriveImageFromFileAndFitToBox

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
private void retriveImageFromFileAndFitToBox(final VBox vboxPhotoList, final File singleFileFromOpenedDialog) {
    LOGGER.info("Open image: ", singleFileFromOpenedDialog.toURI().getPath());
    BufferedImage bufferedImage = null;
    try {
        bufferedImage = ImageIO.read(singleFileFromOpenedDialog);
    } catch (IOException e) {
        e.printStackTrace();
    }
    final Image image = SwingFXUtils.toFXImage(bufferedImage, null);
    final ImageView imageView = new ImageView(image);
    vboxPhotoList.getChildren().clear();
    vboxPhotoList.getChildren().add(imageView);
    vboxPhotoList.setAlignment(Pos.CENTER);
    imageView.setPreserveRatio(true);
    if (imageView.getImage().getHeight() > vboxPhotoList.getHeight() ||
            imageView.getImage().getWidth() > vboxPhotoList.getWidth()) {
        imageView.fitHeightProperty().bind(vboxPhotoList.heightProperty());
        imageView.fitWidthProperty().bind(vboxPhotoList.widthProperty());
    }
    LOGGER.info("Image opened");

}
 
開發者ID:Evegen55,項目名稱:main_carauto_board,代碼行數:23,代碼來源:ImageViewController.java

示例4: openFile

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
private void openFile(File file) {
    try {

        myImageView = new ImageView();
        BufferedImage bufferedImage = ImageIO.read(file);
        Image image = SwingFXUtils.toFXImage(bufferedImage, null);
        myImageView.setImage(image);
        controller.createPictureView(myImageView, image, point);


    } catch (Exception ex) {
        Logger.getLogger(InsertIMG.class.getName()).log(
                Level.SEVERE, null, ex
        );
    }
}
 
開發者ID:kaanburaksener,項目名稱:octoBubbles,代碼行數:17,代碼來源:InsertIMG.java

示例5: asImageViewFX

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
/**
 * convert AWT imageIcon to JavaFX image
 *
 * @param imageIcon
 * @return javaFX image
 */
public static ImageView asImageViewFX(ImageIcon imageIcon) {
    java.awt.Image awtImage = imageIcon.getImage();
    if (awtImage != null) {
        final BufferedImage bImg;
        if (awtImage instanceof BufferedImage) {
            bImg = (BufferedImage) awtImage;
        } else {
            bImg = new BufferedImage(awtImage.getWidth(null), awtImage.getHeight(null), BufferedImage.TYPE_INT_ARGB);
            Graphics2D graphics = bImg.createGraphics();
            graphics.drawImage(awtImage, 0, 0, null);
            graphics.dispose();
        }
        return new ImageView(SwingFXUtils.toFXImage(bImg, null));
    } else
        return null;
}
 
開發者ID:danielhuson,項目名稱:megan-ce,代碼行數:23,代碼來源:CommandManagerFX.java

示例6: getImage

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
/**
 * Get an Image Instance for Use in JavaFX.
 *
 * @return javafx image
 */
public WritableImage getImage() {
    Settings s = new Settings();

    java.awt.Color paper = fxToAWTColor(background);
    java.awt.Color ink = fxToAWTColor(foreground);

    BufferedImage image = new BufferedImage((barcode.getWidth() * zoom) + (2 * border),
            (barcode.getHeight() * zoom) + (2 * border), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.fillRect(0, 0, (barcode.getWidth() * zoom) + (2 * border),
            (barcode.getHeight() * zoom) + (2 * border));

    Java2DRenderer renderer = new Java2DRenderer(g2d, zoom, border, paper, ink);
    renderer.render(barcode);

    return SwingFXUtils.toFXImage(image, null);
}
 
開發者ID:innFactory,項目名稱:JFXC,代碼行數:24,代碼來源:BarcodeFX.java

示例7: handleSaveImageButtonAction

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
private void handleSaveImageButtonAction(ActionEvent event) {
    BufferedImage saveImage = mMenuTerrain.isSelected() ? mTerrainImage : mFantasyImage;

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(mSaveImageButton.getText());
    fileChooser.setInitialDirectory(new File(System.getProperty("user.home"), "Pictures"));
    FileChooser.ExtensionFilter extensionFilter = new FileChooser.ExtensionFilter("PNG", "*.png");
    fileChooser.getExtensionFilters().add(extensionFilter);
    File file = fileChooser.showSaveDialog(mStage);
    if (file != null) {
        try {
            WritableImage writableImage = new WritableImage(saveImage.getWidth(),
                    saveImage.getHeight());
            SwingFXUtils.toFXImage(saveImage, writableImage);
            ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png", file);
        } catch (IOException ioe) {
            Logger.getLogger(TAG).log(Level.SEVERE, null, ioe);
        }
    }
}
 
開發者ID:JelloRanger,項目名稱:MapGenerator,代碼行數:21,代碼來源:UiController.java

示例8: getScaledRGBInstance

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
/**
 * Get a scaled (RGB or ARGB) image, achieving reasonable quality even when scaling down by a considerably amount.
 * 
 * Code is based on https://today.java.net/article/2007/03/30/perils-imagegetscaledinstance
 * 
 * @param img
 * @param targetWidth
 * @param targetHeight
 * @return
 */
static WritableImage getScaledRGBInstance(BufferedImage img, int targetWidth, int targetHeight) {
	int type = (img.getTransparency() == Transparency.OPAQUE) ?
			BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
	
	BufferedImage imgResult = (BufferedImage)img;
	int w = img.getWidth();
	int h = img.getHeight();

	while (w > targetWidth || h > targetHeight) {
		
		w = Math.max(w / 2, targetWidth);
		h = Math.max(h / 2, targetHeight);

		BufferedImage imgTemp = new BufferedImage(w, h, type);
		Graphics2D g2 = imgTemp.createGraphics();
		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
		g2.drawImage(imgResult, 0, 0, w, h, null);
		g2.dispose();

		imgResult = imgTemp;			
	}
	return SwingFXUtils.toFXImage(imgResult, null);
}
 
開發者ID:qupath,項目名稱:qupath,代碼行數:34,代碼來源:ImageOverview.java

示例9: onUpdateCardAction

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
@FXML
public void onUpdateCardAction(ActionEvent event) throws Exception {
	layerBox[0] = layer1Box;
	layerBox[1] = layer2Box;
	layerBox[2] = layer3Box;
	layerBox[3] = layer4Box;
	layerBox[4] = layer5Box;
	layerBox[5] = layer6Box;
	layerBox[6] = layer7Box;
	layerBox[7] = layer8Box;
	layerBox[8] = layer9Box;

	int unitId = Integer.parseInt(idLb.getText());
	boolean[] layerFlag = new boolean[9];
	for(int i = 0; i < layerFlag.length; i++) {
		layerFlag[i] = layerBox[i].isSelected();
	}
	CardImage normalCard = imageService.getNormalCard(unitId, layerFlag);
	CardImage idolizeCard = imageService.getIdolizedCard(unitId, layerFlag);
	WritableImage normalImage = SwingFXUtils.toFXImage(normalCard.getImage(), null);
	WritableImage idolizeImage = SwingFXUtils.toFXImage(idolizeCard.getImage(), null);
	normalCardImage.setImage(normalImage);
	idolizeCardImage.setImage(idolizeImage);
}
 
開發者ID:xwang1024,項目名稱:SIF-Resource-Explorer,代碼行數:25,代碼來源:UnitPreviewStageController.java

示例10: copyBackground

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
private Image copyBackground(Stage stage) {
	final int X = (int) stage.getX();
	final int Y = (int) stage.getY();
	final int W = (int) stage.getWidth();
	final int H = (int) stage.getHeight();

	try {
		java.awt.Robot robot = new java.awt.Robot();
		java.awt.image.BufferedImage image = robot.createScreenCapture(new java.awt.Rectangle(X, Y, W, H));

		return SwingFXUtils.toFXImage(image, null);
	} catch (java.awt.AWTException e) {
		System.out.println("The robot of doom strikes!");
		e.printStackTrace();

		return null;
	}
}
 
開發者ID:mars-sim,項目名稱:mars-sim,代碼行數:19,代碼來源:CrewEditorFX.java

示例11: initCard

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
private void initCard() throws SQLException, IOException {
	boolean[] layerFlag = new boolean[9];
	for (int i = 0; i < layerFlag.length; i++) {
		layerFlag[i] = layerBox[i].isSelected();
	}
	CardImage normalCard = imageService.getNormalCard(unit.getId(), layerFlag);
	CardImage idolizeCard = imageService.getIdolizedCard(unit.getId(), layerFlag);
	// ------ Init layer box ------
	LayerStatus[] normalStatus = normalCard.getLayerStatus();
	LayerStatus[] idolizeStatus = idolizeCard.getLayerStatus();
	for (int i = 0; i < layerFlag.length; i++) {
		if (normalStatus[i] == LayerStatus.DISABLED && idolizeStatus[i] == LayerStatus.DISABLED) {
			layerBox[i].setDisable(true);
		}
	}
	// ----------------------------
	WritableImage normalImage = SwingFXUtils.toFXImage(normalCard.getImage(), null);
	WritableImage idolizeImage = SwingFXUtils.toFXImage(idolizeCard.getImage(), null);
	normalCardImage.setImage(normalImage);
	idolizeCardImage.setImage(idolizeImage);
}
 
開發者ID:xwang1024,項目名稱:SIF-Resource-Explorer,代碼行數:22,代碼來源:UnitPreviewStageBuilder.java

示例12: addKeyImage

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
private void addKeyImage(File imgPath){
	BufferedImage buffer;
	Image img=null;

	if (imgPath!=null){
		try {
			buffer = ImageIO.read(imgPath);
			img=SwingFXUtils.toFXImage(buffer, null);
		} catch (IOException e) {
			new MessagePopUp().showMessageDialog("Couldn't upload Image");
			return;
		}
	}
	ImageView myView=setImageStyle(img);
	myView.relocate(picturePane.getPrefWidth()/2-myView.getFitWidth()/2, picturePane.getPrefHeight()/2-myView.getFitHeight()/2);
	picturePane.getChildren().clear();
	picturePane.getChildren().add(myView);
	setCurrentKeyImage(myView.getImage(), imgPath);
}
 
開發者ID:ngbalk,項目名稱:VOOGASalad,代碼行數:20,代碼來源:KeyFramePopUpPane.java

示例13: drawImage

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
/**
 * Draws the image into the rectangle defined by {@code (x, y, w, h)}.  
 * Note that the {@code observer} is ignored (it is not useful in this
 * context).
 * 
 * @param img  the image ({@code null} permitted...draws nothing).
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 * @param w  the width.
 * @param h  the height.
 * @param observer  ignored.
 * 
 * @return {@code true} if there is no more drawing to be done. 
 */
@Override
public boolean drawImage(final Image img, int x, int y, 
        int w, int h, ImageObserver observer) {
    final BufferedImage buffered;
    if (img instanceof BufferedImage) {
        buffered = (BufferedImage) img;
    } else {
        buffered = new BufferedImage(w, h, 
                BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g2 = buffered.createGraphics();
        g2.drawImage(img, 0, 0, w, h, null);
        g2.dispose();
    }
    javafx.scene.image.WritableImage fxImage = SwingFXUtils.toFXImage(
            buffered, null);
    this.gc.drawImage(fxImage, x, y, w, h);
    return true;
}
 
開發者ID:jfree,項目名稱:fxgraphics2d,代碼行數:33,代碼來源:FXGraphics2D.java

示例14: load

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
public static Image load(NsImageIcon icon) {
    System.setProperty("java.awt.headless", "false");
    java.awt.Image awtImage = Toolkit.getDefaultToolkit().getImage(
            "NSImage://" + icon.getName());
    BufferedImage bufferedImage = null;
    if (awtImage instanceof BufferedImage) {
        bufferedImage = (BufferedImage) awtImage;
    } else {
        bufferedImage = new BufferedImage(awtImage.getWidth(null),
                awtImage.getHeight(null), BufferedImage.TYPE_INT_ARGB);
        Graphics g = bufferedImage.createGraphics();
        g.drawImage(awtImage, 0, 0, null);
        g.dispose();
    }
    return SwingFXUtils.toFXImage(bufferedImage, null);
}
 
開發者ID:cis422s14team5,項目名稱:WatchlistPro,代碼行數:17,代碼來源:NsImageIconLoader.java

示例15: handle

import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
@Override
public void handle(ActionEvent t) {
    FileChooser fileChooser = new FileChooser();

    //Set extension filter
    FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
    FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
    fileChooser.getExtensionFilters().addAll(extFilterJPG, extFilterPNG);

    //Show open file dialog
    File file = fileChooser.showOpenDialog(null);

    try {
        BufferedImage bufferedImage = ImageIO.read(file);
        Image image = SwingFXUtils.toFXImage(bufferedImage, null);
        myImageView.setImage(image);
    } catch (IOException ex) {
        Logger.getLogger(JavaFXPixel.class.getName()).log(Level.SEVERE, null, ex);
    }

}
 
開發者ID:fedevelatec,項目名稱:Pruebas,代碼行數:22,代碼來源:JavaFXPixel.java


注:本文中的javafx.embed.swing.SwingFXUtils.toFXImage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。