下面列出了javafx.scene.image.WritableImage#getHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
}
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);
}
}
}
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);
}
}
/**
* 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;
}
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;
}
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);
}