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();
  }

 

你可能感兴趣的:(java)