本文整理匯總了Java中javafx.embed.swing.SwingFXUtils.fromFXImage方法的典型用法代碼示例。如果您正苦於以下問題:Java SwingFXUtils.fromFXImage方法的具體用法?Java SwingFXUtils.fromFXImage怎麽用?Java SwingFXUtils.fromFXImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.embed.swing.SwingFXUtils
的用法示例。
在下文中一共展示了SwingFXUtils.fromFXImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
}
示例2: 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());
}
}
示例3: writeData
import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
@Override
@BackgroundThread
protected void writeData(@NotNull final VarTable vars, final @NotNull Path resultFile) throws IOException {
super.writeData(vars, resultFile);
final Color color = UIUtils.from(vars.get(PROP_COLOR, ColorRGBA.class));
final int width = vars.getInteger(PROP_WIDTH);
final int height = vars.getInteger(PROP_HEIGHT);
final WritableImage writableImage = new WritableImage(width, height);
final PixelWriter pixelWriter = writableImage.getPixelWriter();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
pixelWriter.setColor(i, j, color);
}
}
final BufferedImage bufferedImage = SwingFXUtils.fromFXImage(writableImage, null);
try (final OutputStream out = Files.newOutputStream(resultFile)) {
ImageIO.write(bufferedImage, "png", out);
}
}
示例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!");
int mtxResult [][] = or(ImageUtil.convertToGreyTone(imagePeer[0]), ImageUtil.convertToGreyTone(imagePeer[1]));
setImage( ImageUtil.toImage( mtxResult ));
System.out.println("OR!");
super.update(getImage());
}
}
示例5: 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());
}
}
示例6: 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();
}
}
}
}
示例7: 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);
}
}
}
示例8: handleFileSaveAction
import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
@FXML
private void handleFileSaveAction(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
File file = fileChooser.showSaveDialog(null);
System.out.println("Saving #" + file + "#");
if (file != null) {
// Stole the following part from:
// http://java-buddy.blogspot.com/2013/04/save-canvas-to-png-file.html
try {
WritableImage writableImage = new WritableImage((int) drawingCanvas.getWidth(), (int) drawingCanvas.getHeight());
drawingCanvas.snapshot(null, writableImage);
RenderedImage renderedImage = SwingFXUtils.fromFXImage(writableImage, null);
// hometask: make sure you can save files in any format (not just png)
// hints: find the extension of the file from the filename, then use substring
ImageIO.write(renderedImage, "png", file);
} catch (IOException ex) {
System.err.println("Couldn't save the file!");
// hometask: throw an alert dialog from here
}
}
}
示例9: addDirection
import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
public void addDirection(String direction, Image tileImage) {
Map<Integer, Image> temp = new HashMap<>();
int range = Math.abs(World.MAX_ELEVATION - World.MIN_ELEVATION);
for (int i = 0; i <= range; i++) {
BufferedImage tile = SwingFXUtils.fromFXImage(tileImage, null);
tile = ImageHelper.editBrightness(tile,
(float) i / (Math.abs(
World.MIN_ELEVATION - World.MAX_ELEVATION) *
2));
tile = ImageHelper.editSaturation(tile,
(float) i / (Math.abs(
World.MIN_ELEVATION - World.MAX_ELEVATION) *
2));
// tile = ImageHelper.editHue(tile, (float) (range - i) / range);
temp.put(i, SwingFXUtils.toFXImage(tile, null));
}
directionImages.put(direction, temp);
}
示例10: getBase64Encoding
import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
private String getBase64Encoding() {
String base64 = null;
if (this.getImage() != null) {
try {
BufferedImage image = SwingFXUtils.fromFXImage(this.getImage(), null);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(image, "png", byteArrayOutputStream);
base64 = new String(Base64.getEncoder().encode(byteArrayOutputStream.toByteArray()));
} catch (IOException exception) {
exception.printStackTrace();
}
}
return base64;
}
示例11: createTask
import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
@Override
protected Task<Attachments> createTask() {
return new Task<Attachments>() {
@Override
protected Attachments call() throws Exception {
final Attachments result = new Attachments();
final Image image = imageView.getImage();
if (image == null) return result;
final BufferedImage swingImage = SwingFXUtils.fromFXImage(imageView.getImage(), null);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ImageFormat format = formatComboBox.getValue();
ImageIO.write(swingImage, format.format, baos);
baos.close();
imageView.setImage(null);
final String filename = Optional.ofNullable(filenameField.getText())
.orElse(defaultFilename()) + format.extension;
result.add(new Attachment(filename, baos.toByteArray()));
return result;
}
};
}
示例12: drawROI
import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
/** @param gc GC for off-screen image
* @param roi RegionOfInterest to draw
*/
private void drawROI(final Graphics2D gc, final RegionOfInterest roi)
{
if (! roi.isVisible())
return;
gc.setColor(GraphicsUtils.convert(roi.getColor()));
final java.awt.geom.Rectangle2D rect = image_area.createIntersection(roiToScreen(roi));
final Image image = roi.getImage();
if (image == null)
gc.drawRect((int)rect.getMinX(), (int)rect.getMinY(), (int)rect.getWidth(), (int)rect.getHeight());
else
{
final BufferedImage awt_image = SwingFXUtils.fromFXImage(image, null);
gc.drawImage(awt_image, (int)rect.getMinX(), (int)rect.getMinY(), (int)rect.getWidth(), (int)rect.getHeight(), null);
}
gc.drawString(roi.getName(), (int)rect.getMinX(), (int)rect.getMinY());
}
示例13: SaveEPS
import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
public void SaveEPS(File file) {
if (!file.getName().endsWith(".eps")) {
file = new File(file.getAbsolutePath() + ".eps");
}
BufferedImage bufImage = SwingFXUtils.fromFXImage(image, null);
Graphics2D g = new EpsGraphics2D();
g.drawImage(bufImage, 0, 0, null);
String epsString = g.toString();
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
bw.write(epsString);
} catch (IOException ex) {
}
}
示例14: changed
import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
@Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
if (newValue.equals(Worker.State.SUCCEEDED)) {
if(webEngine.getDocument().getBaseURI().equals("about:blank")) return;
//If the page loads, let's take a snapshot of it.
WritableImage snapshot = new WritableImage((int) screenSize.getWidth(), (int) screenSize.getHeight());
browser.snapshot(null, snapshot);
BufferedImage renderedImage = SwingFXUtils.fromFXImage(snapshot, null);
//Some math to get a little better thumbnail. Starting x is at 1/4 of the totale page. Goes for a width of half of the screen size to attempt and get the 'core' of the content.
renderedImage = renderedImage.getSubimage((int)(screenSize.getWidth() /4),0,(int)( screenSize.getWidth() / 2 ),(int) screenSize.getHeight() / 2);
saveImage(padPath, fileName, renderedImage);
controller.refreshListView();
urlStage.close();
webEngine.load(null);
}
else if(newValue.equals(Worker.State.FAILED)){
//TODO: Send an error message somehow.
urlStage.close();
}
}
示例15: saveScreenShot
import javafx.embed.swing.SwingFXUtils; //導入方法依賴的package包/類
/**
* Save a screenshot in a user-specified location.
*/
public void saveScreenShot() {
// Save the image in memory.
WritableImage img = canvas.snapshot(new SnapshotParameters(), null);
BufferedImage buffImg = SwingFXUtils.fromFXImage(img, null);
// Open the file Chooser.
File file = fileChooser.showSaveDialog(null);
if (file != null) {
try {
String extension = file.getPath().substring(file.getPath().lastIndexOf('.') + 1);
System.out.println(extension);
ImageIO.write(buffImg, extension, file);
} catch (IOException e) {
e.printStackTrace();
}
}
}