java项目实例图片等比缩放简化

本文主要介绍了如何使用Java进行图片的等比缩放操作,通过创建ImageTest类并在main方法中实现缩放功能。
摘要由CSDN通过智能技术生成

java图片等比缩放

package common;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;

public class ImageCompressionTask implements Runnable{
      
	private InputStream is;
	private String fileName;
	private int width;
	private int height;

	/**
	 * 初始化参数
	 * @param is 图片输入流
	 * @param file  图片
	 * @param fileName  图片名称
	 * @param width   高
	 * @param height  宽
	 */
	public ImageCompressionTask(InputStream is,String fileName,int width,int height) {
		this.is=is;
		this.fileName=fileName;
		this.width=width;
		this.height=height;		
	}
	
	
	
	public void run() {
		// TODO Auto-generated method stub
		try{
			this.compressPic();
		}catch(Exception e){
			System.out.println("文件压缩失败"+e);
		}
		
	}
	
	private String compressPic() throws Exception{
		String path = "E:\\xie\\";//新图片存放路径
		String urlPath =  path + fileName;
		BufferedImage buffImage;
		FileOutputStream output=null;
		BufferedImage compressPic=null;
		try {
			
			String imagetype = "&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值