In the EffectsPlayground sample in javafx.com, there is a function saveImage(node:Node, file:java.io.File), but it does not work in JavaFX 1.2, because the internal implementation details was changed.
I write a new function that works in JavaFX 1.2:
import com.sun.javafx.geom.Bounds2D;
import com.sun.javafx.geom.AffineTransform;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import javafx.scene.*;
import javafx.reflect.*;
import javafx.util.Math;
public function toRenderedImage(node:Node):RenderedImage {
def context = FXLocal.getContext();
def nodeClass = FXLocal.getContext().findClass("javafx.scene.Node");
def getFXNode = nodeClass.getFunction("impl_getPGNode");
def sgNode = (getFXNode.invoke(context.mirrorOf(node)) as FXLocal.ObjectValue).asObject();
def getBounds = sgNode.getClass().getMethod("getCompleteBounds", Bounds2D.class, AffineTransform.class);
def bounds = getBounds.invoke(sgNode, new Bounds2D(), null) as Bounds2D;
def paintMethod = sgNode.getClass().getMethod("render", Graphics2D.class, Bounds2D.class, AffineTransform.class);
def img = new BufferedImage(Math.ceil(bounds.getWidth()), Math.ceil(bounds.getHeight()), BufferedImage.TYPE_INT_RGB);
def g2 = img.createGraphics();
g2.translate(-bounds.x1, -bounds.y1);
paintMethod.invoke(sgNode, g2, bounds, new AffineTransform());
g2.dispose();
img;
}
public function savePNG(node:Node, os:OutputStream) {
ImageIO.write(toRenderedImage(node), "png", os);
}
public function savePNG(node:Node, file:File) {
var savefile;
if (not file.getName().toLowerCase().endsWith(".png")) {
savefile = new File(file.getParent(), "{file.getName()}.png");
} else {
savefile = file;
}
savePNG(node, new FileOutputStream(savefile));
}
分享到:
相关推荐
此样本显示了JsRender Node集成的一些功能,并为使用模板化渲染的自己的Node项目提供了起点。 它还显示了如何将JsRender模板存储在服务器上的文件系统上,然后将它们用于服务器端渲染或客户端渲染,或同时用于两者...
安装好原程序,了世哪个汉化文件《Renderin》放到C:\Program Files\Google\Google SketchUp 8\Plugins\Renderin目录下替换原文件,打开SU8在插件下Renderin菜单点License,在弹出的窗口输入号码,点Apply等一会在...
《Using a Render Pipeline to Render Primitives 使用渲染管道去渲染一个几何体(本例为渲染一个三角形)》一文的示例程序,可以对照文章学习。“可以”直接运行。
It allows you to capture the game view to a multi-channel OpenEXR or multiple PNG files, supporting not just the final output image, but also some common elements, like depth, per-light shadows, ...
jquery renderTo属性实现图片放大镜
render()与render_to_response()均是django中用来显示模板页面的,但是在django1.3之后,render()便比render_to_response()更加招人待见!最明显的就是前者会自动使用RequestContext,而后者需要coding进去, 例如:...
使用fbo来实现render to texture演示
render_to_texture using opengl
Render React components to Sketch .zip,将react组件渲染到草图
RenderDoc是一款基于帧捕获的图形调试器,目前可用于Windows 7-10,Linux和Android上的Vulkan,D3D11,D3D12,OpenGL和OpenGL ES开发。
• Can be controlled using Mecanim, no need to re-write existing code or controllers, just attach a script. • Supports custom animation events. • Built with performance in mind, minimal CPU ...
to exploit rich supervisory signals in the form of 2D annotations like segmentation, we propose a differentiable Render-and-Compare loss that allows 3D shape and pose to be learned with 2D supervision...
in, we process the data and output a template. But before we can output the template we have to wait until all data has been received in order for the template to be processed. This doesn't make any ...
OpenGL渲染到纹理的实现,并有用户交互
ExtJS中的renderTo和applyTo的差别 对applyTo和renderTo的理解和思考个人认为这两篇文章写的不够通俗。写一个简单的例子来看看最终生成了什么代码, 代码如下: <head> <title>RenderTo and ApplyTo</...
(Supports only Built-in Render Pipeline, HDRP/URP are not supported) Shader is made by using an amplify shader editor function, and all logic is in the independent function, therefore you can call ...
richfaces标签render的使用
In publishing and making this document available, PMI is not undertaking to render professional or other services for or on behalf of any person or entity, nor is PMI undertaking to perform any duty ...
render to html