Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
ShenghuoquanBusiness
Project
Project
Details
Activity
Releases
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
bp
ShenghuoquanBusiness
Commits
a88d1585
Commit
a88d1585
authored
Jul 09, 2021
by
yinjiacheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update 图片服务拍照、选择完成后执行压缩
parent
60e493b7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
5 deletions
+16
-5
ImageService.kt
.../src/main/java/com/yidian/common/services/ImageService.kt
+16
-5
No files found.
CommonLib/Common/src/main/java/com/yidian/common/services/ImageService.kt
View file @
a88d1585
...
...
@@ -26,11 +26,13 @@ import java.io.FileInputStream
* description: 图片服务
* 提供调用原生相机拍照、图片选择器、图片预览、图片上传能力
*/
// TODO: 7/9/21 动态获取权限
// TODO: 7/9/21 清除缓存
class
ImageService
:
ZapService
()
{
companion
object
{
private
const
val
TAG
=
"ImageService"
const
val
SERVICE_NAME
=
"
I
mageService"
const
val
SERVICE_NAME
=
"
i
mageService"
// 选择图片
const
val
ACTION_SELECT_PIC
=
"selectImage"
...
...
@@ -108,7 +110,10 @@ class ImageService : ZapService() {
PictureSelector
.
create
(
curTopActivity
)
.
openGallery
(
PictureMimeType
.
ofImage
())
.
imageEngine
(
GlideEngine
.
createGlideEngine
())
.
maxSelectNum
(
SELECT_PIC_MAX_COUNT
-
params
.
maxCount
)
.
maxSelectNum
(
params
.
maxCount
)
.
isWeChatStyle
(
true
)
.
isCompress
(
true
)
.
compressQuality
(
10
)
.
forResult
(
object
:
OnResultCallbackListener
<
LocalMedia
>
{
override
fun
onResult
(
result
:
MutableList
<
LocalMedia
>?)
{
if
(
result
.
isNullOrEmpty
())
{
...
...
@@ -116,12 +121,12 @@ class ImageService : ZapService() {
return
}
cacheSelectedImages
.
addAll
(
result
as
ArrayList
<
LocalMedia
>)
val
picList
=
ArrayList
<
SelectedImageBean
>(
SELECT_PIC_MAX_COUNT
-
params
.
maxCount
)
val
picList
=
ArrayList
<
SelectedImageBean
>(
params
.
maxCount
)
result
.
forEach
{
picList
.
add
(
SelectedImageBean
(
result
[
0
].
id
.
toString
(),
Base64
.
encodeToString
(
FileInputStream
(
it
.
real
Path
).
readBytes
(),
Base64
.
DEFAULT
)
Base64
.
encodeToString
(
FileInputStream
(
it
.
compress
Path
).
readBytes
(),
Base64
.
DEFAULT
)
)
)
}
...
...
@@ -134,6 +139,8 @@ class ImageService : ZapService() {
}
})
// ToastUtils.showShort("请到设置中授予存储空间权限")
// resolver.fail(CODE_PERMISSION_GRANT_FAIL, "check permission READ_EXTERNAL_STORAGE failed", "获取读取外部存储权限失败")
}
/**
...
...
@@ -143,6 +150,8 @@ class ImageService : ZapService() {
PictureSelector
.
create
(
curTopActivity
)
.
openCamera
(
PictureMimeType
.
ofImage
())
.
imageEngine
(
GlideEngine
.
createGlideEngine
())
.
isCompress
(
true
)
.
compressQuality
(
10
)
.
forResult
(
object
:
OnResultCallbackListener
<
LocalMedia
>
{
override
fun
onResult
(
result
:
MutableList
<
LocalMedia
>?)
{
if
(
result
.
isNullOrEmpty
())
{
...
...
@@ -157,7 +166,7 @@ class ImageService : ZapService() {
arrayListOf
(
SelectedImageBean
(
result
[
0
].
id
.
toString
(),
Base64
.
encodeToString
(
FileInputStream
(
result
[
0
].
real
Path
).
readBytes
(),
Base64
.
DEFAULT
)
Base64
.
encodeToString
(
FileInputStream
(
result
[
0
].
compress
Path
).
readBytes
(),
Base64
.
DEFAULT
)
)
)
)
...
...
@@ -169,6 +178,8 @@ class ImageService : ZapService() {
resolver
.
fail
(
CODE_ACTION_CANCEL
,
"take cancel"
,
"拍照取消"
)
}
})
// ToastUtils.showShort("请到设置中授予相机权限")
// resolver.fail(CODE_PERMISSION_GRANT_FAIL, "check permission CAMERA failed", "获取摄像头权限失败")
}
/**
...
...
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