The picture needs to be processed so that it can be displayed in the picture.
After finding some information, the process is also relatively simple code:
/ *
* Andychen (andy.chen.sh@gmail.com)
*
** /
Public Static icon getFixedBoundicon (file imagefile, int hotht, int width "exciption {
Double Ratio = 0.0;
IF (imagefile == null ||! imagefile.isfile ())
Throw New Exception (ImageFile "Is Not Image File Error In GetFixedBoundicon!");
String filepath = imagefile.getpath ();
Icon Ret = New Imageicon (FilePath);
BufferedImage Bi = Imageio.Read (ImageFile);
IF ((bi.getHeight ()> height) || (bi.getwidth ()> width) {
IF (bi.getHeight ()> bi.getwidth ()) {
Ratio = (new integer ()). DoubleValue () /bi.getHeight ();
} else {
Ratio = (New Integer (Width)). DoubleValue () / bi.getwidth ();
}
File THF = New File (FilePath "_" Height "_" width);
Image itemp = bi.getscaledinstance (width, height, bi.scale_smooth);
AffineTransformop Op = New AffineTransformop (AffineTransform.getscaleInstance (Ratio, Ratio), NULL;
Itemp = op.filter (bi, null);
Try {
Imageio.write ((BufferedImage) Itemp, "JPG", THF);
Ret = new imageicon (THF.GetPath ());
} catch (exception ex) {
}
}
Return Ret;
}