本文整理汇总了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);
}
示例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();
}
示例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");
}
示例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
);
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}