public static bufferedimage Resize (int facewidth,bufferedimage srcimg,httpservletrequest request) throws ioexception{
int imgwidth = 0;
if (facewidth>70 && facewidth<120) {
ImgWidth = FACEWIDTH*7/8;
}else if (facewidth>60 && facewidth<70) {
ImgWidth = FACEWIDTH*11/10;
}else if (Facewidth < 60) {
ImgWidth = FACEWIDTH*6/5;
}else{
ImgWidth = FACEWIDTH*4/5;
}
int imgheight = Imgwidth*srcimg.getheight ()/srcimg.getwidth ();
Build a new picture
BufferedImage resizedimg = new BufferedImage (IMGWIDTH,IMGHEIGHT,BUFFEREDIMAGE.TYPE_INT_RGB);
To zoom in or out of the original, draw it down: and keep the PNG image enlarged or smaller the back color is transparent rather than black
Graphics2D resizedg = Resizedimg.creategraphics ();
Resizedimg = Resizedg.getdeviceconfiguration (). Createcompatibleimage (imgwidth,imgheight,transparency.translucent );
Resizedg.dispose ();
RESIZEDG = Resizedimg.creategraphics ();
Image from = Srcimg.getscaledinstance (ImgWidth, ImgHeight, srcimg.scale_area_averaging);
Resizedg.drawimage (from, 0, 0, NULL);
Resizedg.dispose ();
return resizedimg;
}
Solve the problem of the transparent background of Java compressed picture black