⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 histogram.java

📁 功能描述:jsp开发答疑解惑200问题说明
💻 JAVA
字号:
package myBean;

import java.io.*;
import java.util.*;
import javax.imageio.*;
import java.awt.*;
import java.awt.image.*;

public class Histogram {
	public Histogram() {
	}
	
	public double getHistogram(int width, int totalWidth, int height, OutputStream os) {
		
		if(width>totalWidth)
			return 0;
		
		BufferedImage image = new BufferedImage(totalWidth, height, 
									BufferedImage.TYPE_INT_RGB); 

		// 获取图形上下文 
		Graphics g = image.getGraphics(); 

		// 设定背景色 
		g.setColor(new Color(0xFDFDFD)); 
		g.fillRect(0, 0, totalWidth, height); 

		// 画边框 
		g.setColor(Color.black); 
		g.drawRect(0,0,totalWidth-1,height-1);

		// 画柱状图
		g.setColor(Color.blue);
		g.fillRect(0, 0, width, height);
		

		// 释放图形上下文
		g.dispose(); 
		
		try {
			// 输出图象到页面 
			ImageIO.write(image, "JPEG", os);
		} catch (IOException e) {
			return 0;
		}
		
		return (double)width/totalWidth;
	}

/*	
	public static void main(String []args) {
		try{
			BufferedOutputStream os = new BufferedOutputStream(
											new FileOutputStream("c:\\test.jpg"));
											
			new Histogram().getHistogram(180, 200, 20, os);
			os.flush();
			os.close();
		} catch(Exception e) {}
	}
*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -