Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐少华
midjourney-proxy
Commits
dd4041b7
Commit
dd4041b7
authored
Dec 01, 2020
by
郑勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: [1003944] 社群书二维码样式优化
parent
3cd6b662
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
207 additions
and
2 deletions
+207
-2
QrcodeUtils.java
...on/src/main/java/com/pcloud/common/utils/QrcodeUtils.java
+207
-2
No files found.
pcloud-common/src/main/java/com/pcloud/common/utils/QrcodeUtils.java
View file @
dd4041b7
...
@@ -117,7 +117,7 @@ public class QrcodeUtils {
...
@@ -117,7 +117,7 @@ public class QrcodeUtils {
"https://oss.5rs.me/oss/uploadfe/jpg/92f8cf48ae80b099db6580e05d142bea.jpg"
,
false
,
null
,
15036692
));
//#e57114
"https://oss.5rs.me/oss/uploadfe/jpg/92f8cf48ae80b099db6580e05d142bea.jpg"
,
false
,
null
,
15036692
));
//#e57114
styleMap
.
put
(
25
,
new
BackgroudQrDto
(
101
,
95
,
138
,
132
,
styleMap
.
put
(
25
,
new
BackgroudQrDto
(
101
,
95
,
138
,
132
,
"https://oss.5rs.me/oss/uploadfe/jpg/466b40ec470e0dc2094f5967ac7599f3.jpg"
,
true
,
null
,
14171392
));
//#d83d00
"https://oss.5rs.me/oss/uploadfe/jpg/466b40ec470e0dc2094f5967ac7599f3.jpg"
,
true
,
null
,
14171392
));
//#d83d00
styleMap
.
put
(
26
,
new
BackgroudQrDto
(
79
,
118
,
128
,
132
,
/*
styleMap.put(26, new BackgroudQrDto(79, 118, 128, 132,
"https://oss.5rs.me/oss/uploadfe/png/4b2d03e32689ab22c37eec79e5dc21ec.png",false,null,null));//#d83d00
"https://oss.5rs.me/oss/uploadfe/png/4b2d03e32689ab22c37eec79e5dc21ec.png",false,null,null));//#d83d00
styleMap.put(27, new BackgroudQrDto(105, 182, 107, 107,
styleMap.put(27, new BackgroudQrDto(105, 182, 107, 107,
"https://oss.5rs.me/oss/uploadfe/png/325c4a7cf90eb7994c38c2a64116e661.png",false,null,null));//#d83d00
"https://oss.5rs.me/oss/uploadfe/png/325c4a7cf90eb7994c38c2a64116e661.png",false,null,null));//#d83d00
...
@@ -134,7 +134,25 @@ public class QrcodeUtils {
...
@@ -134,7 +134,25 @@ public class QrcodeUtils {
styleMap.put(33, new BackgroudQrDto(69, 113, 135, 135,
styleMap.put(33, new BackgroudQrDto(69, 113, 135, 135,
"https://oss.5rs.me/oss/uploadfe/png/72da7fa4bde1658e58ddfc2a7a13f325.png",false,null,null));//#d83d00
"https://oss.5rs.me/oss/uploadfe/png/72da7fa4bde1658e58ddfc2a7a13f325.png",false,null,null));//#d83d00
styleMap.put(34, new BackgroudQrDto(43, 76, 195, 195,
styleMap.put(34, new BackgroudQrDto(43, 76, 195, 195,
"https://oss.5rs.me/oss/uploadfe/png/b447634d7112cb04c011df8c5424d222.png"
,
false
,
null
,
null
));
//#d83d00
"https://oss.5rs.me/oss/uploadfe/png/b447634d7112cb04c011df8c5424d222.png",false,null,null));//#d83d00*/
styleMap
.
put
(
26
,
new
BackgroudQrDto
(
79
,
118
,
128
,
132
,
"https://oss.raysyun.com/oss/uploadfe/png/4b2d03e32689ab22c37eec79e5dc21ec.png"
,
false
,
null
,
null
));
//#d83d00
styleMap
.
put
(
27
,
new
BackgroudQrDto
(
105
,
182
,
107
,
107
,
"https://oss.raysyun.com/oss/uploadfe/png/325c4a7cf90eb7994c38c2a64116e661.png"
,
false
,
null
,
null
));
//#d83d00
styleMap
.
put
(
28
,
new
BackgroudQrDto
(
97
,
132
,
126
,
126
,
"https://oss.raysyun.com/oss/uploadfe/png/ec836e5053bb08addd8829650701de4a.png"
,
false
,
null
,
null
));
//#d83d00
styleMap
.
put
(
29
,
new
BackgroudQrDto
(
55
,
55
,
189
,
189
,
"https://oss.raysyun.com/oss/uploadfe/png/ea0b71fefed90e33312658d2d221fbad.png"
,
false
,
null
,
null
));
//#d83d00
styleMap
.
put
(
30
,
new
BackgroudQrDto
(
83
,
136
,
141
,
141
,
"https://oss.raysyun.com/oss/uploadfe/png/e0ac4885bcbbd792e2cf4626a2b44455.png"
,
false
,
null
,
null
));
//#d83d00
styleMap
.
put
(
31
,
new
BackgroudQrDto
(
77
,
91
,
139
,
139
,
"https://oss.raysyun.com/oss/uploadfe/png/b8252c1675b9045c90ceef9a80ad8a6e.png"
,
false
,
null
,
null
));
//#d83d00
styleMap
.
put
(
32
,
new
BackgroudQrDto
(
62
,
92
,
175
,
175
,
"https://oss.raysyun.com/oss/uploadfe/png/dbf5919634c81bfd9e271b4c4de3c044.png"
,
false
,
null
,
null
));
//#d83d00
styleMap
.
put
(
33
,
new
BackgroudQrDto
(
69
,
113
,
135
,
135
,
"https://oss.raysyun.com/oss/uploadfe/png/72da7fa4bde1658e58ddfc2a7a13f325.png"
,
false
,
null
,
null
));
//#d83d00
styleMap
.
put
(
34
,
new
BackgroudQrDto
(
43
,
76
,
195
,
195
,
"https://oss.raysyun.com/oss/uploadfe/png/b447634d7112cb04c011df8c5424d222.png"
,
false
,
null
,
null
));
//#d83d00
...
@@ -323,6 +341,32 @@ public class QrcodeUtils {
...
@@ -323,6 +341,32 @@ public class QrcodeUtils {
}
}
}
}
/**
* 创建带颜色的二维码
* @param url
* @param onColor
* @return
* @throws BizException
*/
public
static
String
createColorWithMargin
(
String
url
,
Integer
onColor
,
Integer
marginNum
)
throws
BizException
{
LOGGER
.
info
(
"【二维码】创建带颜色的二维码,<START>.[url]="
+
url
+
"[onClor]="
+
onColor
);
Map
<
EncodeHintType
,
Object
>
hints
=
new
HashMap
<
EncodeHintType
,
Object
>();
hints
.
put
(
EncodeHintType
.
CHARACTER_SET
,
"UTF-8"
);
hints
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
level
);
hints
.
put
(
EncodeHintType
.
MARGIN
,
null
==
marginNum
?
margin
:
marginNum
);
// 设置白边
try
{
// 生成矩阵
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
url
,
BarcodeFormat
.
QR_CODE
,
ImageConstant
.
QRCODE_WITH
,
ImageConstant
.
QRCODE_HEIGHT
,
hints
);
BufferedImage
bufferedImage
=
toBufferedImage
(
bitMatrix
,
onColor
);
bufferedImage
.
flush
();
return
uploadImage
(
bufferedImage
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【二维码】创建二维码失败,<ERROR>:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_UPLOAD_FAILURE
,
"创建二维码失败"
);
}
}
/**
/**
* 创建渐变色二维码
* 创建渐变色二维码
...
@@ -372,6 +416,53 @@ public class QrcodeUtils {
...
@@ -372,6 +416,53 @@ public class QrcodeUtils {
}
}
/**
/**
* 创建渐变色二维码
*
* @param content
* 二维码响应地址
* @return
* @throws Exception
*/
public
static
String
createGradientColorQr
(
String
url
,
Color
newColor
,
Color
oldColor
,
Integer
marginNum
)
throws
BizException
{
LOGGER
.
info
(
"【二维码】创建渐变色二维码,<START>.[url]="
+
url
+
"newColor="
+
newColor
+
"oldColor="
+
oldColor
);
Map
<
EncodeHintType
,
Object
>
hints
=
new
HashMap
<
EncodeHintType
,
Object
>();
hints
.
put
(
EncodeHintType
.
CHARACTER_SET
,
"UTF-8"
);
hints
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
level
);
hints
.
put
(
EncodeHintType
.
MARGIN
,
null
==
marginNum
?
margin
:
marginNum
);
// 设置白边
try
{
// 生成矩阵
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
url
,
BarcodeFormat
.
QR_CODE
,
ImageConstant
.
QRCODE_WITH
,
ImageConstant
.
QRCODE_HEIGHT
,
hints
);
BufferedImage
bufferedImage
=
MatrixToImageWriter
.
toBufferedImage
(
bitMatrix
);
bufferedImage
.
flush
();
// 设置二维码颜色
int
[]
pixels
=
new
int
[
ImageConstant
.
QRCODE_WITH
*
ImageConstant
.
QRCODE_HEIGHT
];
for
(
int
y
=
0
;
y
<
bitMatrix
.
getHeight
();
y
++)
{
for
(
int
x
=
0
;
x
<
bitMatrix
.
getWidth
();
x
++)
{
// 二维码颜色
int
num1
=
(
int
)
(
oldColor
.
getRed
()
-
(
oldColor
.
getRed
()
-
newColor
.
getRed
())
*
1.0
/
bitMatrix
.
getHeight
()
*
(
y
+
1
));
int
num2
=
(
int
)
(
oldColor
.
getGreen
()
-
(
oldColor
.
getGreen
()
-
newColor
.
getGreen
())
*
1.0
/
bitMatrix
.
getHeight
()
*
(
y
+
1
));
int
num3
=
(
int
)
(
oldColor
.
getBlue
()
-
(
oldColor
.
getBlue
()
-
newColor
.
getBlue
())
*
1.0
/
bitMatrix
.
getHeight
()
*
(
y
+
1
));
Color
color
=
new
Color
(
num1
,
num2
,
num3
);
int
colorInt
=
color
.
getRGB
();
// 此处可以修改二维码的颜色,可以分别制定二维码和背景的颜色;
pixels
[
y
*
ImageConstant
.
QRCODE_WITH
+
x
]
=
bitMatrix
.
get
(
x
,
y
)
?
colorInt
:
16777215
;
}
}
BufferedImage
image
=
new
BufferedImage
(
ImageConstant
.
QRCODE_WITH
,
ImageConstant
.
QRCODE_HEIGHT
,
BufferedImage
.
TYPE_INT_RGB
);
image
.
getRaster
().
setDataElements
(
0
,
0
,
ImageConstant
.
QRCODE_WITH
,
ImageConstant
.
QRCODE_HEIGHT
,
pixels
);
return
uploadImage
(
image
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【二维码】创建渐变色二维码失败,<ERROR>:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_UPLOAD_FAILURE
,
"创建渐变色二维码失败"
);
}
}
/**
* 创建带logo二维码
* 创建带logo二维码
*
*
* @param content
* @param content
...
@@ -415,6 +506,49 @@ public class QrcodeUtils {
...
@@ -415,6 +506,49 @@ public class QrcodeUtils {
}
}
/**
/**
* 创建带logo二维码
*
* @param content
* 二维码响应地址
* @return
* @throws Exception
*/
public
static
String
createLogoQr
(
String
url
,
String
logoPath
,
Integer
onColor
,
Integer
marginNum
)
throws
BizException
{
LOGGER
.
info
(
"【二维码】创建带logo二维码,<START>.[url]="
+
url
+
",logoPath="
+
logoPath
+
",onColor="
+
onColor
);
Map
<
EncodeHintType
,
Object
>
hints
=
new
HashMap
<
EncodeHintType
,
Object
>();
hints
.
put
(
EncodeHintType
.
CHARACTER_SET
,
"UTF-8"
);
hints
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
level
);
hints
.
put
(
EncodeHintType
.
MARGIN
,
null
==
marginNum
?
margin
:
marginNum
);
// 设置白边
try
{
// 生成矩阵
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
url
,
BarcodeFormat
.
QR_CODE
,
ImageConstant
.
QRCODE_WITH
,
ImageConstant
.
QRCODE_HEIGHT
,
hints
);
BufferedImage
image
=
toBufferedImage
(
bitMatrix
,
onColor
);
Graphics2D
gs
=
image
.
createGraphics
();
// 载入logo
byte
[]
file
=
FileUtils
.
downloadByteFromUrl
(
logoPath
);
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
file
);
BufferedImage
srcImage
=
ImageIO
.
read
(
in
);
Image
img
=
srcImage
.
getScaledInstance
(
LOGO_WIDTH
,
LOGO_HEIGHT
,
BufferedImage
.
SCALE_SMOOTH
);
int
x
=
(
image
.
getWidth
()
-
LOGO_WIDTH
)
/
2
;
int
y
=
(
image
.
getHeight
()
-
LOGO_HEIGHT
)
/
2
;
gs
.
drawImage
(
img
,
x
,
y
,
LOGO_WIDTH
,
LOGO_HEIGHT
,
null
);
BasicStroke
stroke
=
new
BasicStroke
(
5
,
BasicStroke
.
CAP_ROUND
,
BasicStroke
.
JOIN_ROUND
);
gs
.
setStroke
(
stroke
);
// 设置笔画对象
// 指定弧度的圆角矩形
RoundRectangle2D
.
Float
round
=
new
RoundRectangle2D
.
Float
(
x
,
y
,
LOGO_WIDTH
,
LOGO_HEIGHT
,
20
,
20
);
gs
.
setColor
(
Color
.
WHITE
);
gs
.
draw
(
round
);
// 绘制圆弧矩形
gs
.
dispose
();
img
.
flush
();
return
uploadImage
(
image
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【二维码】创建带logo二维码失败,<ERROR>:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_UPLOAD_FAILURE
,
"创建带logo二维码失败"
);
}
}
/**
* 图片上传文件服务器返回url
* 图片上传文件服务器返回url
*
*
* @param image
* @param image
...
@@ -506,6 +640,77 @@ public class QrcodeUtils {
...
@@ -506,6 +640,77 @@ public class QrcodeUtils {
}
}
/**
* 创建渐变色带logo的二维码
* @param content
* @param srcImagePath
* @return
*/
public
static
String
createGradientColorLogoQr
(
String
content
,
String
srcImagePath
,
Color
newColor
,
Color
oldColor
,
Integer
marginNum
)
{
LOGGER
.
info
(
"【二维码】 创建渐变色带logo的二维码,<START>.[content]="
+
content
+
",srcImagePath="
+
srcImagePath
+
",newColor="
+
newColor
+
"oldColor="
+
oldColor
);
try
{
BufferedImage
scaleImage
=
scale
(
srcImagePath
,
LOGO_WIDTH
,
LOGO_HEIGHT
,
true
);
int
[][]
srcPixels
=
new
int
[
LOGO_WIDTH
][
LOGO_HEIGHT
];
for
(
int
i
=
0
;
i
<
scaleImage
.
getWidth
();
i
++)
{
for
(
int
j
=
0
;
j
<
scaleImage
.
getHeight
();
j
++)
{
srcPixels
[
i
][
j
]
=
scaleImage
.
getRGB
(
i
,
j
);
}
}
Map
<
EncodeHintType
,
Object
>
hint
=
new
HashMap
<
EncodeHintType
,
Object
>();
hint
.
put
(
EncodeHintType
.
CHARACTER_SET
,
"utf-8"
);
hint
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
level
);
hint
.
put
(
EncodeHintType
.
MARGIN
,
null
==
marginNum
?
margin
:
marginNum
);
//设置白边
// 生成二维码
BitMatrix
matrix
=
mutiWriter
.
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
ImageConstant
.
QRCODE_WITH
,
ImageConstant
.
QRCODE_HEIGHT
,
hint
);
deleteWhite
(
matrix
);
// 二维矩阵转为一维像素数组
int
halfW
=
matrix
.
getWidth
()
/
2
;
int
halfH
=
matrix
.
getHeight
()
/
2
;
int
[]
pixels
=
new
int
[
ImageConstant
.
QRCODE_WITH
*
ImageConstant
.
QRCODE_HEIGHT
];
for
(
int
y
=
0
;
y
<
matrix
.
getHeight
();
y
++)
{
for
(
int
x
=
0
;
x
<
matrix
.
getWidth
();
x
++)
{
// 左上角颜色,根据自己需要调整颜色范围和颜色
if
(
x
>
halfW
-
IMAGE_HALF_WIDTH
&&
x
<
halfW
+
IMAGE_HALF_WIDTH
&&
y
>
halfH
-
IMAGE_HALF_WIDTH
&&
y
<
halfH
+
IMAGE_HALF_WIDTH
)
{
pixels
[
y
*
ImageConstant
.
QRCODE_WITH
+
x
]
=
srcPixels
[
x
-
halfW
+
IMAGE_HALF_WIDTH
][
y
-
halfH
+
IMAGE_HALF_WIDTH
];
}
else
if
((
x
>
halfW
-
IMAGE_HALF_WIDTH
-
FRAME_WIDTH
&&
x
<
halfW
-
IMAGE_HALF_WIDTH
+
FRAME_WIDTH
&&
y
>
halfH
-
IMAGE_HALF_WIDTH
-
FRAME_WIDTH
&&
y
<
halfH
+
IMAGE_HALF_WIDTH
+
FRAME_WIDTH
)
||
(
x
>
halfW
+
IMAGE_HALF_WIDTH
-
FRAME_WIDTH
&&
x
<
halfW
+
IMAGE_HALF_WIDTH
+
FRAME_WIDTH
&&
y
>
halfW
-
IMAGE_HALF_WIDTH
-
FRAME_WIDTH
&&
y
<
halfH
+
IMAGE_HALF_WIDTH
+
FRAME_WIDTH
)
||
(
x
>
halfW
-
IMAGE_HALF_WIDTH
-
FRAME_WIDTH
&&
x
<
halfW
+
IMAGE_HALF_WIDTH
+
FRAME_WIDTH
&&
y
>
halfH
-
IMAGE_HALF_WIDTH
-
FRAME_WIDTH
&&
y
<
halfH
-
IMAGE_HALF_WIDTH
+
FRAME_WIDTH
)
||
(
x
>
halfW
-
IMAGE_HALF_WIDTH
-
FRAME_WIDTH
&&
x
<
halfW
+
IMAGE_HALF_WIDTH
+
FRAME_WIDTH
&&
y
>
halfH
+
IMAGE_HALF_WIDTH
-
FRAME_WIDTH
&&
y
<
halfH
+
IMAGE_HALF_WIDTH
+
FRAME_WIDTH
))
{
pixels
[
y
*
ImageConstant
.
QRCODE_WITH
+
x
]
=
0xfffffff
;
// 在图片四周形成边框
}
else
{
// 二维码颜色 13 72 107 50 165 162
int
num1
=
(
int
)
(
oldColor
.
getRed
()
-
(
oldColor
.
getRed
()
-
newColor
.
getRed
())*
1.0
/
matrix
.
getHeight
()
*
(
y
+
1
));
int
num2
=
(
int
)
(
oldColor
.
getGreen
()
-
(
oldColor
.
getGreen
()
-
newColor
.
getGreen
())*
1.0
/
matrix
.
getHeight
()
*
(
y
+
1
));
int
num3
=
(
int
)
(
oldColor
.
getBlue
()
-
(
oldColor
.
getBlue
()
-
newColor
.
getBlue
())
*
1.0
/
matrix
.
getHeight
()
*
(
y
+
1
));
Color
color
=
new
Color
(
num1
,
num2
,
num3
);
int
colorInt
=
color
.
getRGB
();
// 此处可以修改二维码的颜色,可以分别制定二维码和背景的颜色;
pixels
[
y
*
ImageConstant
.
QRCODE_WITH
+
x
]
=
matrix
.
get
(
x
,
y
)
?
colorInt
:
16777215
;
// 0x000000:0xffffff
}
}
}
BufferedImage
image
=
new
BufferedImage
(
ImageConstant
.
QRCODE_WITH
,
ImageConstant
.
QRCODE_HEIGHT
,
BufferedImage
.
TYPE_INT_RGB
);
image
.
getRaster
().
setDataElements
(
0
,
0
,
ImageConstant
.
QRCODE_WITH
,
ImageConstant
.
QRCODE_HEIGHT
,
pixels
);
return
uploadImage
(
image
);
}
catch
(
BizException
e
)
{
throw
new
BizException
(
e
.
getCode
(),
e
.
getMessage
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【二维码】创建渐变色带logo的二维码失败,<ERROR>:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_UPLOAD_FAILURE
,
"创建渐变色带logo的二维码失败"
);
}
}
private
static
BufferedImage
scale
(
String
srcImageFile
,
int
height
,
private
static
BufferedImage
scale
(
String
srcImageFile
,
int
height
,
int
width
,
boolean
hasFiller
)
throws
IOException
,
BizException
{
int
width
,
boolean
hasFiller
)
throws
IOException
,
BizException
{
...
...
Write
Preview
Markdown
is supported
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