• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

在服务器端动态生成gif or jpg示例

servlet/jsp 搞代码 7年前 (2018-06-18) 223次浏览 已收录 0个评论

package web.images;

/**
* 此处插入类型描述。
* 创建日期:(2002-6-6 9:59:00)
* @author:Administrator

http://www.gaodaima.com/41159.html在服务器端动态生成gif or jpg示例

*/
import java.io.*;

import java.util.*;

import com.sun.image.codec.jpeg.*;

import java.awt.image.*;

import java.awt.*;

public class ChartGraphics {

BufferedImage image;

public void createImage(String fileLocation) {

try {

FileOutputStream fos = new FileOutputStream(fileLocation);

BufferedOutputStream bos = new BufferedOutputStream(fos);

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);

encoder.encode(image);

bos.close();

} catch(Exception e) {

System.out.println(e);

}

}

public void graphicsGeneration(int h1,int h2,int h3,int h4,int h5) {

final int X=10;

int imageWidth = 800;//图片的宽度

int imageHeight =900;//图片的高度

int columnWidth=70;//柱的宽度

int columnHeight=800;//柱的最大高度

ChartGraphics chartGraphics = new ChartGraphics();

chartGraphics.image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);

Graphics graphics = chartGraphics.image.getGraphics();

graphics.setColor(Color.white);

graphics.fillRect(0,0,imageWidth,imageHeight);

graphics.setColor(Color.black);
//graphics.setXORMode(Color.blue);
graphics.drawLine(columnWidth+X,columnHeight-h5-50,columnWidth+X,columnHeight);//Y轴

graphics.drawLine(columnWidth+X,columnHeight-h5-50,columnWidth+X-10,columnHeight-h5-40);//Y轴箭头左

graphics.drawLine(columnWidth+X,columnHeight-h5-50,columnWidth+X+10,columnHeight-h5-40);//Y轴箭头右

graphics.drawLine(750,columnHeight,columnWidth+X,columnHeight);//X轴

graphics.drawLine(750,columnHeight,740,columnHeight-10);//X轴

graphics.drawLine(750,columnHeight,740,columnHeight+10);//X轴

graphics.setColor(Color.yellow);

graphics.fillRect(X+1*columnWidth+10, columnHeight-h1, columnWidth, h1);

graphics.fillRect(X+2*columnWidth+20, columnHeight-h2, columnWidth, h2);

graphics.fillRect(X+3*columnWidth+30, columnHeight-h3, columnWidth, h3);

graphics.fillRect(X+4*columnWidth+40, columnHeight-h4, columnWidth, h4);

graphics.fillRect(X+5*columnWidth+50, columnHeight-h5, columnWidth, h5);

//graphics.drawString()

chartGraphics.createImage("D://leaderquery//leaderqueryWeb//web800//images//chart.jpg");

}

}

欢迎大家阅读《在服务器端动态生成gif or jpg示例》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:在服务器端动态生成gif or jpg示例

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址