cutpic.java
来自「Java源代码,使用JBulider开发的上传类,可以上传图片,铃声.」· Java 代码 · 共 48 行
JAVA
48 行
package com.owner.demo;import java.io.File;import java.io.FileOutputStream;import java.awt.Graphics;import java.awt.Image;import java.awt.image.BufferedImage;import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEGImageEncoder;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2006</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class CutPic { public CutPic() { } public void cutSize() { try { File file = new File("C://tempphoto//post-15-1144514217.jpg"); Image src = javax.imageio.ImageIO.read(file); //构造Image对象 int wideth = src.getWidth(null); //得到源图宽 int height = src.getHeight(null); //得到源图长 BufferedImage tag = new BufferedImage(128,128,BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(src,0,0,128,128,null); FileOutputStream out = new FileOutputStream("C://tempphoto//post1.jpg"); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } catch(Exception ex) { ex.printStackTrace(); } } public static void main(String[] args) { CutPic cutPic1 = new CutPic(); cutPic1.cutSize(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?