Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
b27f5e7c
Commit
b27f5e7c
authored
Aug 15, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
媒体工具类
parent
7077b92f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
ch-core/src/main/java/com/wwdz/ch/core/entity/ImageInfo.java
ch-core/src/main/java/com/wwdz/ch/core/entity/ImageInfo.java
+17
-0
ch-core/src/main/java/com/wwdz/ch/core/util/MediaUtil.java
ch-core/src/main/java/com/wwdz/ch/core/util/MediaUtil.java
+41
-0
No files found.
ch-core/src/main/java/com/wwdz/ch/core/entity/ImageInfo.java
0 → 100644
View file @
b27f5e7c
package
com.wwdz.ch.core.entity
;
import
com.xxdxxs.entity.Entity
;
import
lombok.Data
;
@Data
public
class
ImageInfo
implements
Entity
{
private
int
height
;
private
int
width
;
public
String
formartString
()
{
return
this
.
width
+
"x"
+
this
.
height
;
}
}
ch-core/src/main/java/com/wwdz/ch/core/util/MediaUtil.java
View file @
b27f5e7c
package
com.wwdz.ch.core.util
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.entity.ImageInfo
;
import
com.xxdxxs.utils.CommonUtils
;
import
com.xxdxxs.utils.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -10,6 +13,7 @@ import java.io.ByteArrayInputStream;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
public
class
MediaUtil
{
...
...
@@ -36,6 +40,36 @@ public class MediaUtil {
}
public
static
ImageInfo
getImageSize
(
InputStream
inputStream
)
{
try
{
BufferedImage
bufferedImage
=
ImageIO
.
read
(
inputStream
);
ImageInfo
imageInfo
=
new
ImageInfo
();
imageInfo
.
setHeight
(
bufferedImage
.
getHeight
());
imageInfo
.
setHeight
(
bufferedImage
.
getWidth
());
return
imageInfo
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取图片尺寸出错 : {}"
,
e
);
}
return
null
;
}
public
static
ImageInfo
getImageSize
(
String
imageUrl
)
{
try
{
URL
url
=
new
URL
(
imageUrl
);
InputStream
inputStream
=
url
.
openStream
();
BufferedImage
bufferedImage
=
ImageIO
.
read
(
inputStream
);
ImageInfo
imageInfo
=
new
ImageInfo
();
imageInfo
.
setHeight
(
bufferedImage
.
getHeight
());
imageInfo
.
setWidth
(
bufferedImage
.
getWidth
());
return
imageInfo
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取图片尺寸出错 : {}"
,
e
);
}
return
null
;
}
/**
* 将BufferedImage转换为InputStream
*
...
...
@@ -52,4 +86,11 @@ public class MediaUtil {
}
return
null
;
}
public
static
void
main
(
String
[]
args
)
{
String
vedioUrl
=
"https://cdn.wanwudezhi.com/static/web-static/video/53596700878a572ca4fae35243aaa819.mp4"
;
String
url
=
getImageByCutVedio
(
vedioUrl
);
ImageInfo
imageInfo
=
getImageSize
(
url
);
System
.
out
.
println
(
imageInfo
.
formartString
());
}
}
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