本文整理汇总了Java中javafx.scene.image.WritableImage类的典型用法代码示例。如果您正苦于以下问题:Java WritableImage类的具体用法?Java WritableImage怎么用?Java WritableImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WritableImage类属于javafx.scene.image包,在下文中一共展示了WritableImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: take
import javafx.scene.image.WritableImage; //导入依赖的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: renderImage
import javafx.scene.image.WritableImage; //导入依赖的package包/类
private static void renderImage(WritableImage img, double gridSize, double hueFactor, double hueOffset) {
PixelWriter pw = img.getPixelWriter();
double w = img.getWidth();
double h = img.getHeight();
double xRatio = 0.0;
double yRatio = 0.0;
double hue = 0.0;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
xRatio = x/w;
yRatio = y/h;
hue = Math.sin(yRatio*(gridSize*Math.PI))*Math.sin(xRatio*(gridSize*Math.PI))*Math.tan(hueFactor/20.0)*360.0 + hueOffset;
Color c = Color.hsb(hue, 1.0, 1.0);
pw.setColor(x, y, c);
}
}
}
示例3: updateColorBar
import javafx.scene.image.WritableImage; //导入依赖的package包/类
/** Update color bar in UI from current 'map' */
private void updateColorBar()
{
// On Mac OS X it was OK to create an image sized 256 x 1:
// 256 wide to easily set the 256 colors,
// 1 pixel height which is then stretched via the BackgroundSize().
// On Linux, the result was garbled unless the image height matched the
// actual height, so it's now fixed to COLOR_BAR_HEIGHT
final WritableImage colors = new WritableImage(256, COLOR_BAR_HEIGHT);
final PixelWriter writer = colors.getPixelWriter();
for (int x=0; x<256; ++x)
{
final int arfb = ColorMappingFunction.getRGB(map.getColor(x));
for (int y=0; y<COLOR_BAR_HEIGHT; ++y)
writer.setArgb(x, y, arfb);
}
// Stretch image to fill color_bar
color_bar.setBackground(new Background(
new BackgroundImage(colors, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT,
BackgroundPosition.DEFAULT,
new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, true, true))));
}
示例4: resizeCanvas
import javafx.scene.image.WritableImage; //导入依赖的package包/类
public static Image resizeCanvas(Image imageSource, int newWidth, int newHeight, int offsetX, int offsetY) {
int sourceWidth = (int) imageSource.getWidth();
int sourceHeight = (int) imageSource.getHeight();
// No work needed here...
if (sourceWidth == newWidth && sourceHeight == newHeight)
return imageSource;
WritableImage outputImage = new WritableImage(newWidth, newHeight);
PixelReader pixelReader = imageSource.getPixelReader();
PixelWriter pixelWriter = outputImage.getPixelWriter();
WritablePixelFormat<IntBuffer> format = WritablePixelFormat.getIntArgbInstance();
int[] buffer = new int[sourceWidth * sourceHeight];
pixelReader.getPixels(0, 0, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);
pixelWriter.setPixels(offsetX, offsetY, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);
return outputImage;
}
示例5: chartsToImages
import javafx.scene.image.WritableImage; //导入依赖的package包/类
/**
* Converts charts to Java {@link WritableImage}s
*
* @param charts the charts to be converted to {@link WritableImage}s
* @return a {@link List} of {@link WritableImage}s
*/
private List<WritableImage> chartsToImages(List<Chart> charts) {
List<WritableImage> chartImages = new ArrayList<>();
// Scaling the chart image gives it a higher resolution
// which results in a better image quality when the
// image is exported to the pdf
SnapshotParameters snapshotParameters = new SnapshotParameters();
snapshotParameters.setTransform(new Scale(2, 2));
for (Chart chart : charts) {
chartImages.add(chart.snapshot(snapshotParameters, null));
}
return chartImages;
}
示例6: handleFileSaveAction
import javafx.scene.image.WritableImage; //导入依赖的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);
}
}
}
示例7: handleFileSaveAction
import javafx.scene.image.WritableImage; //导入依赖的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
}
}
}
示例8: updatePlaceholder
import javafx.scene.image.WritableImage; //导入依赖的package包/类
private void updatePlaceholder(Node newView) {
if (view.getWidth() > 0 && view.getHeight() > 0) {
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
Image placeholderImage = view.snapshot(parameters,
new WritableImage((int) view.getWidth(), (int) view.getHeight()));
placeholder.setImage(placeholderImage);
placeholder.setFitWidth(placeholderImage.getWidth());
placeholder.setFitHeight(placeholderImage.getHeight());
} else {
placeholder.setImage(null);
}
placeholder.setVisible(true);
placeholder.setOpacity(1.0);
view.getChildren().setAll(placeholder, newView);
placeholder.toFront();
}
示例9: saveSnapshot
import javafx.scene.image.WritableImage; //导入依赖的package包/类
public static boolean saveSnapshot(QuPathViewer viewer, File file) {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
javafx.scene.canvas.Canvas canvas = viewer.getCanvas();
WritableImage image = new WritableImage((int)canvas.getWidth(), (int)canvas.getHeight());
image = canvas.snapshot(new SnapshotParameters(), image);
try {
ImageIO.write(SwingFXUtils.fromFXImage(image, null ),
"png",
byteOutput);
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(byteOutput.toByteArray());
fileOutputStream.close();
byteOutput.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
示例10: updateHeatMap
import javafx.scene.image.WritableImage; //导入依赖的package包/类
private void updateHeatMap() {
monochromeCanvas.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);
heatMap = new WritableImage(monochromeImage.widthProperty().intValue(), monochromeImage.heightProperty().intValue());
PixelWriter pixelWriter = heatMap.getPixelWriter();
PixelReader pixelReader = monochromeImage.getPixelReader();
Color colorFromMonoChromeImage;
double brightness;
Color mappedColor;
for (int y = 0 ; y < monochromeImage.getHeight() ; y++) {
for (int x = 0 ; x < monochromeImage.getWidth(); x++) {
colorFromMonoChromeImage = pixelReader.getColor(x, y);
//brightness = computeLuminance(colorFromMonoChromeImage.getRed(), colorFromMonoChromeImage.getGreen(), colorFromMonoChromeImage.getBlue());
//brightness = computeBrightness(colorFromMonoChromeImage.getRed(), colorFromMonoChromeImage.getGreen(), colorFromMonoChromeImage.getBlue());
brightness = computeBrightnessFast(colorFromMonoChromeImage.getRed(), colorFromMonoChromeImage.getGreen(), colorFromMonoChromeImage.getBlue());
mappedColor = getColorAt(mappingGradient, brightness);
if (fadeColors) {
//pixelWriter.setColor(x, y, Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness));
pixelWriter.setColor(x, y, Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), colorFromMonoChromeImage.getOpacity()));
} else {
pixelWriter.setColor(x, y, mappedColor);
}
}
}
heatMapView.setImage(heatMap);
}
示例11: HeatMap
import javafx.scene.image.WritableImage; //导入依赖的package包/类
public HeatMap(final double WIDTH, final double HEIGHT, ColorMapping COLOR_MAPPING, final double EVENT_RADIUS, final boolean FADE_COLORS, final double HEAT_MAP_OPACITY, final OpacityDistribution OPACITY_DISTRIBUTION) {
super();
SNAPSHOT_PARAMETERS.setFill(Color.TRANSPARENT);
eventList = new ArrayList();
eventImages = new HashMap<>();
colorMapping = COLOR_MAPPING;
mappingGradient = colorMapping.mapping;
fadeColors = FADE_COLORS;
radius = EVENT_RADIUS;
opacityDistribution = OPACITY_DISTRIBUTION;
eventImage = createEventImage(radius, opacityDistribution);
monochrome = new Canvas(WIDTH, HEIGHT);
ctx = monochrome.getGraphicsContext2D();
monochromeImage = new WritableImage((int) WIDTH, (int) HEIGHT);
setImage(heatMap);
setMouseTransparent(true);
setOpacity(HEAT_MAP_OPACITY);
registerListeners();
}
示例12: updateHeatMap
import javafx.scene.image.WritableImage; //导入依赖的package包/类
/**
* Recreates the heatmap based on the current monochrome map.
* Using this approach makes it easy to change the used color
* mapping.
*/
private void updateHeatMap() {
monochrome.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);
heatMap = new WritableImage(monochromeImage.widthProperty().intValue(), monochromeImage.heightProperty().intValue());
Color colorFromMonoChromeImage;
double brightness;
Color mappedColor;
PixelWriter pixelWriter = heatMap.getPixelWriter();
PixelReader pixelReader = monochromeImage.getPixelReader();
int width = (int) monochromeImage.getWidth();
int height = (int) monochromeImage.getHeight();
for (int y = 0 ; y < height ; y++) {
for (int x = 0 ; x < width ; x++) {
colorFromMonoChromeImage = pixelReader.getColor(x, y);
brightness = colorFromMonoChromeImage.getOpacity();
mappedColor = getColorAt(mappingGradient, brightness);
pixelWriter.setColor(x, y, fadeColors ? Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness) : mappedColor);
}
}
setImage(heatMap);
}
示例13: HeatMap
import javafx.scene.image.WritableImage; //导入依赖的package包/类
public HeatMap(final double WIDTH, final double HEIGHT, ColorMapping COLOR_MAPPING, final double SPOT_RADIUS, final boolean FADE_COLORS, final double HEAT_MAP_OPACITY, final OpacityDistribution OPACITY_DISTRIBUTION) {
super();
SNAPSHOT_PARAMETERS.setFill(Color.TRANSPARENT);
spotList = new ArrayList<>();
spotImages = new HashMap<>();
colorMapping = COLOR_MAPPING;
mappingGradient = colorMapping.getGradient();
fadeColors = FADE_COLORS;
radius = SPOT_RADIUS;
opacityDistribution = OPACITY_DISTRIBUTION;
spotImage = createSpotImage(radius, opacityDistribution);
monochrome = new Canvas(WIDTH, HEIGHT);
ctx = monochrome.getGraphicsContext2D();
monochromeImage = new WritableImage((int) WIDTH, (int) HEIGHT);
setImage(heatMap);
setMouseTransparent(true);
setOpacity(HEAT_MAP_OPACITY);
registerListeners();
}
示例14: updateHeatMap
import javafx.scene.image.WritableImage; //导入依赖的package包/类
/**
* Recreates the heatmap based on the current monochrome map.
* Using this approach makes it easy to change the used color
* mapping.
*/
private void updateHeatMap() {
monochrome.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);
int width = monochromeImage.widthProperty().intValue();
int height = monochromeImage.heightProperty().intValue();
heatMap = new WritableImage(width, height);
Color colorFromMonoChromeImage;
double brightness;
Color mappedColor;
PixelWriter pixelWriter = heatMap.getPixelWriter();
PixelReader pixelReader = monochromeImage.getPixelReader();
for (int y = 0 ; y < height ; y++) {
for (int x = 0 ; x < width ; x++) {
colorFromMonoChromeImage = pixelReader.getColor(x, y);
brightness = colorFromMonoChromeImage.getOpacity();
mappedColor = Helper.getColorAt(mappingGradient, brightness);
pixelWriter.setColor(x, y, fadeColors ? Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness) : mappedColor);
}
}
setImage(heatMap);
}
示例15: validate
import javafx.scene.image.WritableImage; //导入依赖的package包/类
@Override
@FXThread
protected boolean validate(@NotNull final VarTable vars) {
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);
}
}
getImageView().setImage(writableImage);
return true;
}