ByteArrayOutputStream baos = new ByteArrayOutputStream();
VerifyCodeUtil.outputImage(100, 39, baos, code);
final String BASE64_IMAGE = “data:image/jpeg;base64,%s”;
String base64Img = String.format(BASE64_IMAGE, Base64Util.encode(baos.toByteArray()));
return base64Img;
}
/**
-
生成指定验证码图像文件
-
@param w
-
@param h
-
@param outputFile
-
@param code
-
@throws IOException
*/
public static void outputImage(int w, int h, File outputFile, String code) throws IOException {
if (outputFile == null) {
return;
}
File dir = outputFile.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
try {
outputFile.createNewFile();
FileOutputStream fos = new FileOutputStream(outputFile);
outputImage(w, h, fos, code);
fos.close();
} catch (IOException e) {
throw e;
}
}
/**
-
输出指定验证码图片流
-
@param w
-
@param h
-
@param os
-
@param code
-
@throws IOException
*/
public static voi