Java Code Examples for javafx.scene.image.WritableImage#getHeight()

The following examples show how to use javafx.scene.image.WritableImage#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageOperatorSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 2
Source File: ImageOperatorSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 3
Source File: PrintAction.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void print(final Node node)
{
    try
    {
        // Select printer
        final PrinterJob job = Objects.requireNonNull(PrinterJob.createPrinterJob(), "Cannot create printer job");
        final Scene scene = Objects.requireNonNull(node.getScene(), "Missing Scene");

        if (! job.showPrintDialog(scene.getWindow()))
            return;

        // Get Screenshot
        final WritableImage screenshot = node.snapshot(null, null);

        // Scale image to full page
        final Printer printer = job.getPrinter();
        final Paper paper = job.getJobSettings().getPageLayout().getPaper();
        final PageLayout pageLayout = printer.createPageLayout(paper,
                                                               PageOrientation.LANDSCAPE,
                                                               Printer.MarginType.DEFAULT);
        final double scaleX = pageLayout.getPrintableWidth() / screenshot.getWidth();
        final double scaleY = pageLayout.getPrintableHeight() / screenshot.getHeight();
        final double scale = Math.min(scaleX, scaleY);
        final ImageView print_node = new ImageView(screenshot);
        print_node.getTransforms().add(new Scale(scale, scale));

        // Print off the UI thread
        JobManager.schedule(Messages.Print, monitor ->
        {
            if (job.printPage(print_node))
                job.endJob();
        });
    }
    catch (Exception ex)
    {
        ExceptionDetailsErrorDialog.openError(node, Messages.Print, Messages.PrintErr, ex);
    }
}
 
Example 4
Source File: Utils.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get an image filled with the specified colour.
 * <p/>
 * @param color the colour of the image.
 * @return the image.
 */
public static Image getImageFromColour(final Color color) {
	WritableImage image = new WritableImage(2, 2);
	PixelWriter writer = image.getPixelWriter();
	for (int i = 0; i < image.getWidth(); i++) {
		for (int j = 0; j < image.getHeight(); j++) {
			writer.setColor(i, j, color);
		}
	}
	return image;
}
 
Example 5
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static Image createImage(int width, int height, Color color) {
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();
    for (int y = 0; y < newImage.getHeight(); y++) {
        for (int x = 0; x < newImage.getWidth(); x++) {
            pixelWriter.setColor(x, y, color);
        }
    }
    return newImage;
}
 
Example 6
Source File: DragAndDropHandler.java    From FxDock with Apache License 2.0 5 votes vote down vote up
protected static Image createDragImage(FxDockPane client)
{
	SnapshotParameters sp = new SnapshotParameters();
	sp.setFill(Color.TRANSPARENT);
	
	WritableImage im = client.snapshot(sp, null);

	if(client.isPaneMode())
	{
		return im;
	}
	
	// include selected tab
	FxDockTabPane tp = (FxDockTabPane)DockTools.getParent(client);
	Node n = tp.lookup(".tab:selected");
	WritableImage tim = n.snapshot(sp, null);
	
	double dy = tim.getHeight();
	
	// must adjust for the tab
	deltay += dy;
	
	double w = Math.max(im.getWidth(), tim.getWidth());
	double h = im.getHeight() + dy;
	Canvas c = new Canvas(w, h);
	GraphicsContext g = c.getGraphicsContext2D();
	g.drawImage(tim, 0, 0);
	g.drawImage(im, 0, dy);
	return c.snapshot(sp, null);
}