/**
* Edit picture according to wide height
*
* @param Outpath
* Output File path
* @param width
* Output File width
* @param height
* High Output file
* @throws Exception
*/
public static void Dealimage (String filePath, String outpath, Integer width,
Integer height) throws Exception {
To read a local file:
InputStream is = new FileInputStream (FilePath);
Determine the image size 0---500k for 4 times times compression----1024k 6 times times compression 1024 more than 8 times times compression
File picture = new file (FilePath);
int cutmultiple = 2;
if (picture.exists ()) {
int picsize =integer.parseint (new DecimalFormat ("0"). Format (Picture.length ()/1024.0);//rounding
try {
int picsize = (int) (Picture.length ()/1024.0);//Non-rounding
if (picsize<=512) {
cutmultiple=4;
}else if (picsize>512 && picsize<=1024) {
cutmultiple=6;
}else if (picsize>1024) {
cutmultiple=8;
}
} catch (Exception e) {//False fault tolerant processing
cutmultiple=2;
}
}
Image image = Imageio.read (IS);
float tagsize = 200;
int old_w = Image.getwidth (null);
int old_h = Image.getheight (null);
int tempsize;
BufferedImage tag = new BufferedImage (old_w/cutmultiple, Old_h/cutmultiple, Bufferedimage.type_int_rgb);
Tag.getgraphics (). DrawImage (image, 0, 0, old_w/cutmultiple, old_h/cutmultiple, NULL);
FileOutputStream newimage = new FileOutputStream (Outpath);
JPEGImageEncoder encoder = Jpegcodec.createjpegencoder (newimage);
Encoder.encode (tag);
Newimage.close ();
}
Java Picture High quality compression