fix image.write slow

This commit is contained in:
walkertest 2019-06-27 20:08:00 +08:00 committed by GitHub
parent b390fe3f3f
commit 2d68b0f89b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -6,6 +6,8 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
/** /**
* png格式验证码 * png格式验证码
@ -92,7 +94,9 @@ public class SpecCaptcha extends Captcha {
g.setFont(font.deriveFont(num(2) == 0 ? Font.PLAIN : Font.ITALIC)); g.setFont(font.deriveFont(num(2) == 0 ? Font.PLAIN : Font.ITALIC));
g.drawString(String.valueOf(strs[i]), x, y); g.drawString(String.valueOf(strs[i]), x, y);
} }
ImageIO.write(bi, "png", out); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outputStream);
encoder.encode(bi);
// ImageIO.write(bi, "png", out);
out.flush(); out.flush();
ok = true; ok = true;
} catch (IOException e) { } catch (IOException e) {
@ -107,4 +111,4 @@ public class SpecCaptcha extends Captcha {
} }
return ok; return ok;
} }
} }