Create graphics via R + JavaGD (JRI) in Java
来源:互联网 发布:如何加入淘宝网热卖 编辑:程序博客网 时间:2024/06/01 09:03
通过 JavaGD 创建 R 图像
File 1
import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import javax.swing.JButton;import javax.swing.JFrame;import org.rosuda.JRI.Rengine;import org.rosuda.javaGD.GDCanvas;public class TryR4 extends JFrame implements ActionListener{/** * */private static final long serialVersionUID = 1L;private Rengine engine;public static GDCanvas gdc;private JButton jbgo;private int counter;public TryR4(){super.setTitle("My R Plot");super.setSize(600, 600); // initialize GUI jbgo = new JButton("Go"); gdc = new GDCanvas(600,600); jbgo.addActionListener(this); this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(jbgo,BorderLayout.PAGE_START); this.getContentPane().add(gdc,BorderLayout.PAGE_END); this.pack(); // initialize R engine = new Rengine(new String[] {"--vanilla"}, false, null); engine.eval(".setenv <- if (exists(\"Sys.setenv\")) Sys.setenv else Sys.putenv"); engine.eval(".setenv(\"JAVAGD_CLASS_NAME\"=\"TryR4Interface\")"); engine.eval("library(JavaGD)"); this.setVisible(true);// initialize sth elsecounter = 1;}public static void main(String args[]){new TryR4();}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif(e.getSource() == jbgo){engine.eval("JavaGD()");engine.eval("a <- rnorm(100)");engine.eval("plot(a,type=\"l\")");gdc.initRefresh();// save it to fileFile f = new File("c:\\playaround\\play2.png"); BufferedImage buffImg = new BufferedImage(gdc.getWidth(), gdc.getHeight(),BufferedImage.TYPE_INT_RGB);gdc.paintAll(buffImg.createGraphics()); try {ImageIO.write(buffImg, "png", f);} catch (IOException ex) {// TODO Auto-generated catch blockex.printStackTrace();}this.setTitle("Random number (" + String.valueOf(counter) + ")");counter ++;}}}
File 2 - Interface
import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import org.rosuda.javaGD.GDInterface;public class TryR4Interface extends GDInterface { public void gdOpen(double w, double h) { c = TryR4.gdc; }}
- Create graphics via R + JavaGD (JRI) in Java
- java通过JRI调用R自定义脚本
- Java调用R方法之一:JRI(Java/R Interface)
- 从Java里调用R – JRI的设置方法
- 从Java里调用R – JRI的设置方法
- java调用R语言包(JRI方式),bug记录
- [R] Expression in R graphics
- Create dump via taskmgr in XP
- JRI方式实现Java和R连接--关键点在配置环境变量,重启Eclipse
- 配置:jri与java结合
- [Putty] Running R and MATLAB in linux via putty
- Create MOS via ffmpeg
- Create subtask in task list via client javascript in sharepoint 2013
- BeagleBone Black: Graphics via VNC
- Create/Delete list via powershell
- Via composer create Laravel project
- R learning -Base Graphics
- install oracle java 7 in ubuntu via ppa
- Magento "Source model metarobots/product_attribute_source_unit not found for attribute"
- Ext Combobox 显示valueField值 不显示displayField问题
- linux交换分区回收
- 关于Java中extends,implements的几点问题
- C语言内存管理相关知识点
- Create graphics via R + JavaGD (JRI) in Java
- U3d插件——Swarm Object Manager分析(三)SwarmItemManager(未完)
- 三角肌前束(01):直臂前平举
- 日历控件&在线编辑器
- Android在标准linux基础上对休眠唤醒的实现(一)
- 学习java,,,你应该研究的
- 异或操作
- 四色定理(本人本科论文题目)
- Hanoi--汉诺塔问题