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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
23 deletions
+38
-23
ImageCombined.java
...haoban/manage/service/context/combined/ImageCombined.java
+38
-23
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 {
return
null
;
}
BufferedImage
combinedImage
=
generateImage
(
largeImage
,
qrCodeImage
,
showStyle
,
lineOne
,
lineTwo
);
if
(
combinedImage
==
null
)
{
return
null
;
}
// ImageIO.write(combinedImage, "jpg", new File(OUTPUT_PATH));
try
(
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
())
{
...
...
@@ -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
(
"合成图片开始"
);
int
width
=
image
.
getWidth
();
...
...
@@ -192,31 +195,43 @@ public class ImageCombined {
width
=
Math
.
max
(
width
,
MIN_WIDTH
);
}
int
finalHeight
=
height
+
(
showStyle
==
1
?
0
:
WHITE_SPACE_HEIGHT
);
BufferedImage
resizedQRCode
=
null
;
BufferedImage
resizedImage
=
null
;
BufferedImage
combinedImage
=
new
BufferedImage
(
width
,
finalHeight
,
BufferedImage
.
TYPE_INT_RGB
);
BufferedImage
resizedImage
=
Thumbnails
.
of
(
image
)
.
size
(
width
,
height
).
asBufferedImage
();
Graphics2D
g
=
combinedImage
.
createGraphics
();
g
.
setColor
(
Color
.
WHITE
);
g
.
drawImage
(
resizedImage
,
0
,
1
,
null
);
if
(
showStyle
==
1
)
{
qrWidth
=
width
*
QR_WIDTH_REFERENCE
/
750
;
}
BufferedImage
resizedQRCode
=
Thumbnails
.
of
(
qrCode
).
size
(
qrWidth
,
qrWidth
).
asBufferedImage
();
try
{
BufferedImage
combinedImage
=
new
BufferedImage
(
width
,
finalHeight
,
BufferedImage
.
TYPE_INT_RGB
);
if
(
showStyle
==
1
)
{
qrWidth
=
width
*
QR_WIDTH_REFERENCE
/
750
;
}
resizedQRCode
=
Thumbnails
.
of
(
qrCode
).
size
(
qrWidth
,
qrWidth
).
asBufferedImage
();
resizedImage
=
Thumbnails
.
of
(
image
).
size
(
width
,
height
).
asBufferedImage
();
Graphics2D
g
=
combinedImage
.
createGraphics
();
g
.
setColor
(
Color
.
WHITE
);
g
.
drawImage
(
resizedImage
,
0
,
1
,
null
);
if
(
showStyle
==
1
)
{
// 不需要留白时,QR码距离底部20px
g
.
drawImage
(
resizedQRCode
,
width
-
qrWidth
-
20
,
finalHeight
-
qrWidth
-
20
,
null
);
}
else
{
// 需要留白时
addWhiteSpace
(
g
,
width
,
finalHeight
,
resizedQRCode
,
qrWidth
,
lineOne
,
lineTwo
);
}
if
(
showStyle
==
1
)
{
// 不需要留白时,QR码距离底部20px
g
.
drawImage
(
resizedQRCode
,
width
-
qrWidth
-
20
,
finalHeight
-
qrWidth
-
20
,
null
);
}
else
{
// 需要留白时
addWhiteSpace
(
g
,
width
,
finalHeight
,
resizedQRCode
,
qrWidth
,
lineOne
,
lineTwo
);
g
.
dispose
();
logger
.
info
(
"合成图片结束"
);
return
combinedImage
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"生成合成图像时发生异常:"
,
e
);
return
null
;
}
finally
{
if
(
resizedQRCode
!=
null
)
{
resizedQRCode
.
flush
();
}
if
(
resizedImage
!=
null
)
{
resizedImage
.
flush
();
}
}
g
.
dispose
();
logger
.
info
(
"合成图片结束"
);
return
combinedImage
;
}
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