Java 制作缩略图

本文介绍了一种使用Java进行图片处理的方法,包括如何读取图片、获取图片尺寸,并将图片进行复制及格式转换。
try {
			//读取图片数据
			String path = "e:\\tab.gif";
			
			File file = new File(path);
			
			BufferedImage image = ImageIO.read(file);
			
			int width = image.getWidth();
			int height = image.getHeight();
			
			//System.out.println("高是:"+width+"宽是:"+height);
			
			//写图片信息
			Image img = image.getScaledInstance(width, height, Image.SCALE_DEFAULT);
			
			BufferedImage oImage = new BufferedImage(width, height, Image.SCALE_DEFAULT);
			
			oImage.getGraphics().drawImage(img, 0, 0, null);
			
			File oFile = new File("e:\\abc.gif");
			
			ImageIO.write(oImage, "gif", oFile);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
下面的附件是jar包
使用方式如下:
try {
   CopyImage copy = new CopyImage("e:\\1.gif", "e:\\new1.jpg", "jpg", 0, 0);
   copy.copy();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值