資源描述:
《JAVA上傳圖片自動縮放處理》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在教育資源-天天文庫。
1、/**??*?縮略圖實現(xiàn),將圖片(jpg、bmp、png、gif等等)真實的變成想要的大小??*/?packagecom.bean;???importjava.awt.Image;??importjava.awt.image.BufferedImage;??importjava.io.File;??importjava.io.FileOutputStream;??importjava.io.IOException;??importjavax.imageio.ImageIO;??importcom.sun.image.codec.jpeg.JPEGCodec;??imp
2、ortcom.sun.image.codec.jpeg.JPEGImageEncoder;???/*******************************************************************************??*縮略圖類(通用)本java類能將jpg、bmp、png、gif圖片文件,進行等比或非等比的大小轉(zhuǎn)換。具體使用方法??*compressPic(大圖片路徑,生成小圖片路徑,大圖片文件名,生成小圖片文名,生成小圖片寬度,生成小圖片高度,是否等比縮放(默認為true))??*/??publicclassCompres
3、sPicDemo{???????privateFilefile=null;//文件對象???????privateStringinputDir;//輸入圖路徑??????privateStringoutputDir;//輸出圖路徑??????privateStringinputFileName;//輸入圖文件名??????privateStringoutputFileName;//輸出圖文件名??????privateintoutputWidth=100;//默認輸出圖片寬??????privateintoutputHeight=100;//默認輸出圖片高??????
4、privatebooleanproportion=true;//是否等比縮放標記(默認為等比縮放)??????publicCompressPicDemo(){//初始化變量??????????inputDir="";???????????outputDir="";???????????inputFileName="";???????????outputFileName="";???????????outputWidth=100;???????????outputHeight=100;???????}???????publicvoidsetInputDir(String
5、inputDir){???????????this.inputDir=inputDir;???????}???????publicvoidsetOutputDir(StringoutputDir){???????????this.outputDir=outputDir;???????}???????publicvoidsetInputFileName(StringinputFileName){???????????this.inputFileName=inputFileName;??????}???????publicvoidsetOutputFileName(Str
6、ingoutputFileName){???????????this.outputFileName=outputFileName;???????}???????publicvoidsetOutputWidth(intoutputWidth){??????????this.outputWidth=outputWidth;???????}???????publicvoidsetOutputHeight(intoutputHeight){???????????this.outputHeight=outputHeight;???????}???????publicvoidse
7、tWidthAndHeight(intwidth,intheight){???????????this.outputWidth=width;??????????this.outputHeight=height;???????}??????????????/*???????*獲得圖片大小???????*傳入?yún)?shù)Stringpath:圖片路徑???????*/???????publiclonggetPicSize(Stringpath){???????????file=newFile(path);???????????returnfile.length(