這是我前兩天寫的生成圖片的縮略圖和給圖片打上logo的java代碼
import java
import java
import java
import java
import java
import java
import java
import java
import java
import java
//生成縮略圖和給圖上打上公司logo
public static void main(String[] args) throws IOException {
//源文件
String pathS=
//目標文件
String pathD=
//拷貝文件
copyfile(pathS
//
//生成縮小mimi圖
File stadimgfile
//圖片緩存
BufferedImage img
//得到圖片的寬和高
double width = img
double height = img
int miniwidth =
int miniheight =
double ratew = miniwidth / width;
double rateh = miniheight / height;
//獲得適合的縮放比率
double rate = Math
rate = (Math
BufferedImage imgmini = new java
Graphics
gmini
gmini
AffineTransform trans = new AffineTransform();
trans
AffineTransformOp op = new AffineTransformOp(trans
gmini
ImageIO
//
//mimi圖加水印
BufferedImage img
int mimi_width
int mimi_height
BufferedImage imgmimi
BufferedImage
//logo文件的位置
String logoFile =
BufferedImage watermark
Graphics
gmimi
gmimi
ImageIO
}
// 使用FileInputStream和FileOuStream
public static void copyfile(String pathSrc
{
FileInputStream fi=new FileInputStream(pathSrc);
FileOutputStream fo=new FileOutputStream(pathDest);
byte data[]=new byte[fi
fi
fo
fi
fo
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26025.html