import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class ImageTest {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
String srcImageFile="C:\\Documents and Settings\\Administrator\\桌面\\asdfdfdfdf_fgfsg78s74.psd";
//String srcImageFile="C:\\Documents and Settings\\Administrator\\桌面\\用来上传\\1.jpg";
// int scale = 0;
// try {
// BufferedImage src = ImageIO.read(new File(srcImageFile)); // 读入文件
// System.out.println(new File(srcImageFile));
// System.out.println(src);
// int width = src.getWidth(); // 得到源图宽
// int height = src.getHeight(); // 得到源图长
//
// System.out.println(width);
// System.out.println(height);
// if(width >scale){
// height = scale*height/width;
// width = scale;
// }
// if(true){
// return;
// }
// //height = (int)(scale);
// Image image = src.getScaledInstance(width, height,
// Image.SCALE_DEFAULT);
// BufferedImage tag = new BufferedImage(width, height,
// BufferedImage.TYPE_INT_RGB);
// Graphics g = tag.getGraphics();
// g.drawImage(image, 0, 0, null); // 绘制缩小后的图
// g.dispose();
// ImageIO.write(tag, "JPEG", new File(srcImageFile));// 输出到文件流
// } catch (IOException e) {
// e.printStackTrace();
// }
Psd r = new Psd();
r.read(srcImageFile);
System.out.println("*****");
int n = r.getFrameCount();
System.out.println("************"+n);
for (int i = 0; i < n; i++) {
BufferedImage image = r.getLayer(i);
Point offset = r.getLayerOffset(i);
// do something with image
String outFilePath = "c:\\testPsd_"+i+".jpg";
FileOutputStream out = new FileOutputStream(outFilePath);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
}
}
}
| 4 JAVA图片处理 | 2008-05-14 19:00:00 |