<%@ page contentType="text/html; charset=gb2312"%> java生成JPEG 图像文件
网站公告:   ◆北天JAVA技术网热情为java爱好者服务,本网内容包括JAVA(JSP、servlet、EJB、webservice、j2ee、javabean、应用服务器、JavaScript),数据库(MYSQL、SQL Server、Sybase、Oracle、DB2、数据库综合知识),设计研究(设计模式、Struts、Spring、Hibernate、设计框架、设计综合知识),WEB2.0新技术(主要介绍AJAX),以及各种技术的入门、实例、例子等等,欢迎各位多来坐坐!◆  诚邀各位JAVA爱好者加盟!◆  本网站内容丰富,更新快,保证每周20篇以上!  
加入收藏
设为首页
联系站长
承接项目
  相关资源:网站首页 | 免费培训学院 | 技术论坛 | JAVA聊天室 | 作家专栏 | 开发工具 | 认证考试 | 会员俱乐部
  JAVA技术初学者园地 | jsp与servlet | javascript | Java源代码 | EJB | web service | 应用服务器 | JAVA综合知识
  设计研究设计模式 | 设计框架 | Struts | Spring | Hibernate | 开源项目 | 面向对象设计 | 设计综合知识
  数 据 库MYSQL | SQL Server | Sybase | Oracle | DB2 | Informix | Access | 数据库综合知识
  其他资源:AJAX新技术 | 网站开发 | ERP软件 | OA办公软件 | 商业智能BI | 开发综合知识 | 承接项目 | 项目试用

 
 
java生成JPEG 图像文件
     发布者: 发布时间:2006-07-26
java生成JPEG 图像文件. 代码如下:

我的这段代码主要提供给我自己编写的工作流设计器对象使用(EWorkFlowControl ewf), EWorkFlowControl 继承了JComponent重载了绘制的方法,如果有兄弟需要用到这个功能的,只需要将EWorkFlowControl 替换成自己的JComponent对象即可。

/** 使当前输入的工作流对象上的图形生成JPEG 图像文件.

* 每一个节点对应一个图片.

* 建立的文件存放在jar 文件文件夹下,并创建一个子文件夹

* 以节点的名称为文件夹的名称.

* @param ewf 需要生成jpeg图片文件的工作流对象.

* @return boolean: 返回一个布尔值,表示是否保存成功.

*/

public static boolean buildThePictrue(EWorkFlowControl ewf)

{

//modify by mw

//列出流程中所有的node节点.

//分别设置这些节点为选中状态,并存成图片(名称为节点的流水号)

INode rootNode = ewf.getNote(); Rectangle bounds = ewf.getBounds();

INode[] children = rootNode.getNodeChildren();

int childrenLen = rootNode.getNodeChildCount();

String nodeNumber = null;

boolean flag = true;

//消除所有节点得选中状态.

for(int j = 0; j < childrenLen; j++) {

children[j].setSelect(false); }

//生成总图(我是一个节点一个图像)

try {

java.awt.image.BufferedImage image; image = new java.awt.image.BufferedImage(bounds.width, bounds.height, java.awt.image.BufferedImage.TYPE_INT_RGB);

Graphics g = image.getGraphics(); g.setColor(Color.white);

g.fillRect(0, 0, bounds.width, bounds.height);

ewf.paintComponent(g);

String path = System.getProperty("user.dir") +System.getProperty("file.separator") +ewf.getWorkFlowName() +"["+ewf.getWorkFlowCode()+"]";

File fd = new File(path);

if (!fd.exists()) {

fd.mkdirs();

}

String filePath = path + System.getProperty("file.separator")+"0.jpeg";

File imgFile = new File(filePath);

FileOutputStream fos = new FileOutputStream(imgFile);

BufferedOutputStream bos = new BufferedOutputStream(fos);

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);

encoder.encode(image); bos.close();

}

catch(Exception ex) {

flag = false;

}

//到此第一个图像已经生成!

//循环生成图片

for(int i = 0; i < childrenLen; i++)

{

nodeNumber = children[i].getNodeNumber();

if (nodeNumber == null)

{

flag = false; continue;

} else {

children[i].setSelect(true);

try {

java.awt.image.BufferedImage image; image = new java.awt.image.BufferedImage(bounds.width, bounds.height, java.awt.image.BufferedImage.TYPE_INT_RGB);

Graphics g = image.getGraphics();

g.setColor(Color.white);

g.fillRect(0, 0, bounds.width, bounds.height);

ewf.paintComponent(g);

String path = System.getProperty("user.dir") +System.getProperty("file.separator") +ewf.getWorkFlowName() +"["+ewf.getWorkFlowCode()+"]";

File fd = new File(path);

if (!fd.exists()) {

fd.mkdirs();

}

String filePath = path + System.getProperty("file.separator")+nodeNumber+".jpeg";

File imgFile = new File(filePath);

FileOutputStream fos = new FileOutputStream(imgFile);

BufferedOutputStream bos = new BufferedOutputStream(fos); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);

encoder.encode(image); bos.close();

children[i].setSelect(false);

} catch(Exception ex) {

flag = false;

} } }

if (flag) {

new ExceptionDialog(PIC_SAVE_OK,PIC_SAVE_DIALOG_TITLE, DesktopFrame.getCurrentInstance(), true).setVisible(true);

} else {

new ExceptionDialog(PIC_SAVE_ERROR,PIC_SAVE_DIALOG_TITLE, DesktopFrame.getCurrentInstance(), true).setVisible(true);

}

return flag;

}

(转载文章请保留出处:北天JAVA技术网(www.java114.com))
 
更多精彩文章:
Excel的java处理方式
将文本格式的文章转换为html/xml格式文本的功能封装到Javabean
java中,this用途总结。。。
开放源码-SMTP发信客户端 for Java
java JDBC 提高程序可移植性
递归函数之JAVA演绎
 
        
标 题:   
内 容:   
 
                                  
 
免责声明:该文章由网友发表,如果对您造成侵权,请联系站长

首页 - 承接项目 - 网站地图 - 联系我们 -
版权所有北天JAVA技术工作室 ICP证号:粤ICP备06079815号