Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
git test
Jfinal
Commits
68b6dd7d
Commit
68b6dd7d
authored
3 years ago
by
James
Browse files
Options
Download
Email Patches
Plain Diff
jfinal 5.0.0 release ^_^
parent
01db766d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/com/jfinal/captcha/CaptchaRender.java
+11
-9
src/main/java/com/jfinal/captcha/CaptchaRender.java
src/main/java/com/jfinal/ext/render/CaptchaRender.java
+7
-6
src/main/java/com/jfinal/ext/render/CaptchaRender.java
with
18 additions
and
15 deletions
+18
-15
src/main/java/com/jfinal/captcha/CaptchaRender.java
+
11
-
9
View file @
68b6dd7d
...
...
@@ -147,15 +147,16 @@ public class CaptchaRender extends Render {
// 字体抗锯齿
g
.
setRenderingHint
(
RenderingHints
.
KEY_TEXT_ANTIALIASING
,
RenderingHints
.
VALUE_TEXT_ANTIALIAS_ON
);
ThreadLocalRandom
random
=
ThreadLocalRandom
.
current
();
// 设定背景色
g
.
setColor
(
getRandColor
(
210
,
250
));
g
.
setColor
(
getRand
om
Color
(
210
,
250
,
random
));
g
.
fillRect
(
0
,
0
,
WIDTH
,
HEIGHT
);
ThreadLocalRandom
random
=
ThreadLocalRandom
.
current
();
//绘制小字符背景
Color
color
=
null
;
for
(
int
i
=
0
;
i
<
20
;
i
++){
color
=
getRandColor
(
120
,
200
);
color
=
getRand
om
Color
(
120
,
200
,
random
);
g
.
setColor
(
color
);
String
rand
=
String
.
valueOf
(
charArray
[
random
.
nextInt
(
charArray
.
length
)]);
g
.
drawString
(
rand
,
random
.
nextInt
(
WIDTH
),
random
.
nextInt
(
HEIGHT
));
...
...
@@ -176,7 +177,7 @@ public class CaptchaRender extends Render {
//旋转区域
g
.
rotate
(
Math
.
toRadians
(
degree
),
x
,
y
);
//设定字体颜色
color
=
getRandColor
(
20
,
130
);
color
=
getRand
om
Color
(
20
,
130
,
random
);
g
.
setColor
(
color
);
//将认证码显示到图象中
g
.
drawString
(
String
.
valueOf
(
randomString
.
charAt
(
i
)),
x
+
8
,
y
+
10
);
...
...
@@ -198,12 +199,13 @@ public class CaptchaRender extends Render {
/*
* 给定范围获得随机颜色
*/
protected
Color
getRandColor
(
int
fc
,
int
bc
)
{
ThreadLocalRandom
random
=
ThreadLocalRandom
.
current
();
if
(
fc
>
255
)
protected
Color
getRandomColor
(
int
fc
,
int
bc
,
ThreadLocalRandom
random
)
{
if
(
fc
>
255
)
{
fc
=
255
;
if
(
bc
>
255
)
}
if
(
bc
>
255
)
{
bc
=
255
;
}
int
r
=
fc
+
random
.
nextInt
(
bc
-
fc
);
int
g
=
fc
+
random
.
nextInt
(
bc
-
fc
);
int
b
=
fc
+
random
.
nextInt
(
bc
-
fc
);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/jfinal/ext/render/CaptchaRender.java
+
7
-
6
View file @
68b6dd7d
...
...
@@ -86,13 +86,13 @@ public class CaptchaRender extends Render {
// 生成随机类
ThreadLocalRandom
random
=
ThreadLocalRandom
.
current
();
// 设定背景色
g
.
setColor
(
getRandColor
(
200
,
250
));
g
.
setColor
(
getRand
om
Color
(
200
,
250
,
random
));
g
.
fillRect
(
0
,
0
,
WIDTH
,
HEIGHT
);
// 设定字体
g
.
setFont
(
new
Font
(
"Times New Roman"
,
Font
.
PLAIN
,
18
));
// 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
g
.
setColor
(
getRandColor
(
160
,
200
));
g
.
setColor
(
getRand
om
Color
(
160
,
200
,
random
));
for
(
int
i
=
0
;
i
<
155
;
i
++)
{
int
x
=
random
.
nextInt
(
WIDTH
);
int
y
=
random
.
nextInt
(
HEIGHT
);
...
...
@@ -121,12 +121,13 @@ public class CaptchaRender extends Render {
/*
* 给定范围获得随机颜色
*/
private
Color
getRandColor
(
int
fc
,
int
bc
)
{
ThreadLocalRandom
random
=
ThreadLocalRandom
.
current
();
if
(
fc
>
255
)
private
Color
getRandomColor
(
int
fc
,
int
bc
,
ThreadLocalRandom
random
)
{
if
(
fc
>
255
)
{
fc
=
255
;
if
(
bc
>
255
)
}
if
(
bc
>
255
)
{
bc
=
255
;
}
int
r
=
fc
+
random
.
nextInt
(
bc
-
fc
);
int
g
=
fc
+
random
.
nextInt
(
bc
-
fc
);
int
b
=
fc
+
random
.
nextInt
(
bc
-
fc
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment