java jpeg_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++)

{

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值