?? piczoom.java
字號:
package org.sunxin.lesson.jsp.util;
import java.awt.Color;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import javax.swing.ImageIcon;
public class PicZoom
{
public static BufferedImage zoom(String srcFileName,
int outputWidth,
int outputHeight)
{
//使用源圖像文件名創建ImageIcon對象。
ImageIcon imgIcon=new ImageIcon(srcFileName);
//得到Image對象。
Image img=imgIcon.getImage();
return zoom(img,outputWidth,outputHeight);
}
public static BufferedImage zoom(Image srcImage,
int outputWidth,
int outputHeight)
{
BufferedImage buffImg=new BufferedImage(outputWidth,outputHeight,
BufferedImage.TYPE_INT_RGB);
//創建Graphics2D對象,用于在BufferedImage對象上繪圖。
Graphics2D g=buffImg.createGraphics();
//設置圖形上下文當前的顏色為白色。
g.setColor(Color.WHITE);
//用圖形上下文中的當前顏色填充指定的舉行區域。
g.fillRect(0,0,outputWidth,outputHeight);
//按照縮放的大小在BufferedImage對象上繪制原始圖像。
g.drawImage(srcImage,0,0,outputWidth,outputHeight,null);
//釋放圖形上下文使用的系統資源。
g.dispose();
return buffImg;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -