Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
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
haoban3.0
haoban-manage3.0
Commits
93de13ef
Commit
93de13ef
authored
Oct 29, 2024
by
王祖波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
合成优化
parent
e0f7d146
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
8 deletions
+23
-8
ImageCombined.java
...haoban/manage/service/context/combined/ImageCombined.java
+23
-8
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/context/combined/ImageCombined.java
View file @
93de13ef
...
@@ -126,6 +126,9 @@ public class ImageCombined {
...
@@ -126,6 +126,9 @@ public class ImageCombined {
return
null
;
return
null
;
}
}
BufferedImage
combinedImage
=
generateImage
(
largeImage
,
qrCodeImage
,
showStyle
,
lineOne
,
lineTwo
);
BufferedImage
combinedImage
=
generateImage
(
largeImage
,
qrCodeImage
,
showStyle
,
lineOne
,
lineTwo
);
if
(
combinedImage
==
null
)
{
return
null
;
}
// ImageIO.write(combinedImage, "jpg", new File(OUTPUT_PATH));
// ImageIO.write(combinedImage, "jpg", new File(OUTPUT_PATH));
try
(
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
())
{
try
(
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
())
{
...
@@ -173,7 +176,7 @@ public class ImageCombined {
...
@@ -173,7 +176,7 @@ public class ImageCombined {
});
});
}
}
private
static
BufferedImage
generateImage
(
BufferedImage
image
,
BufferedImage
qrCode
,
int
showStyle
,
String
lineOne
,
String
lineTwo
)
throws
Exception
{
private
static
BufferedImage
generateImage
(
BufferedImage
image
,
BufferedImage
qrCode
,
int
showStyle
,
String
lineOne
,
String
lineTwo
){
logger
.
info
(
"合成图片开始"
);
logger
.
info
(
"合成图片开始"
);
int
width
=
image
.
getWidth
();
int
width
=
image
.
getWidth
();
...
@@ -192,19 +195,20 @@ public class ImageCombined {
...
@@ -192,19 +195,20 @@ public class ImageCombined {
width
=
Math
.
max
(
width
,
MIN_WIDTH
);
width
=
Math
.
max
(
width
,
MIN_WIDTH
);
}
}
int
finalHeight
=
height
+
(
showStyle
==
1
?
0
:
WHITE_SPACE_HEIGHT
);
int
finalHeight
=
height
+
(
showStyle
==
1
?
0
:
WHITE_SPACE_HEIGHT
);
BufferedImage
resizedQRCode
=
null
;
BufferedImage
resizedImage
=
null
;
try
{
BufferedImage
combinedImage
=
new
BufferedImage
(
width
,
finalHeight
,
BufferedImage
.
TYPE_INT_RGB
);
BufferedImage
combinedImage
=
new
BufferedImage
(
width
,
finalHeight
,
BufferedImage
.
TYPE_INT_RGB
);
if
(
showStyle
==
1
)
{
BufferedImage
resizedImage
=
Thumbnails
.
of
(
image
)
qrWidth
=
width
*
QR_WIDTH_REFERENCE
/
750
;
.
size
(
width
,
height
).
asBufferedImage
();
}
resizedQRCode
=
Thumbnails
.
of
(
qrCode
).
size
(
qrWidth
,
qrWidth
).
asBufferedImage
();
resizedImage
=
Thumbnails
.
of
(
image
).
size
(
width
,
height
).
asBufferedImage
();
Graphics2D
g
=
combinedImage
.
createGraphics
();
Graphics2D
g
=
combinedImage
.
createGraphics
();
g
.
setColor
(
Color
.
WHITE
);
g
.
setColor
(
Color
.
WHITE
);
g
.
drawImage
(
resizedImage
,
0
,
1
,
null
);
g
.
drawImage
(
resizedImage
,
0
,
1
,
null
);
if
(
showStyle
==
1
)
{
qrWidth
=
width
*
QR_WIDTH_REFERENCE
/
750
;
}
BufferedImage
resizedQRCode
=
Thumbnails
.
of
(
qrCode
).
size
(
qrWidth
,
qrWidth
).
asBufferedImage
();
if
(
showStyle
==
1
)
{
if
(
showStyle
==
1
)
{
// 不需要留白时,QR码距离底部20px
// 不需要留白时,QR码距离底部20px
...
@@ -217,6 +221,17 @@ public class ImageCombined {
...
@@ -217,6 +221,17 @@ public class ImageCombined {
g
.
dispose
();
g
.
dispose
();
logger
.
info
(
"合成图片结束"
);
logger
.
info
(
"合成图片结束"
);
return
combinedImage
;
return
combinedImage
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"生成合成图像时发生异常:"
,
e
);
return
null
;
}
finally
{
if
(
resizedQRCode
!=
null
)
{
resizedQRCode
.
flush
();
}
if
(
resizedImage
!=
null
)
{
resizedImage
.
flush
();
}
}
}
}
private
static
void
addWhiteSpace
(
Graphics2D
g
,
int
width
,
int
finalHeight
,
BufferedImage
qrCode
,
int
qrWidth
,
String
lineOne
,
String
lineTwo
)
{
private
static
void
addWhiteSpace
(
Graphics2D
g
,
int
width
,
int
finalHeight
,
BufferedImage
qrCode
,
int
qrWidth
,
String
lineOne
,
String
lineTwo
)
{
...
...
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