Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CFFP-HB
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chao Sun
CFFP-HB
Commits
998cb72c
Commit
998cb72c
authored
Jul 29, 2025
by
yuzhenWang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改海报
parent
ffb43c6d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
5 deletions
+42
-5
myPackageA/poster/poster.vue
+42
-5
No files found.
myPackageA/poster/poster.vue
View file @
998cb72c
...
...
@@ -211,10 +211,15 @@ export default {
// 调用工具函数生成图片
const
imageData
=
await
elementToImage
(
element
);
this
.
generatedImage
=
imageData
;
// 将生成的图片保存到本地存储
uni
.
setStorageSync
(
'savedShareImage'
,
imageData
);
// 压缩图片
const
compressedImage
=
await
this
.
compressImage
(
imageData
);
this
.
generatedImage
=
compressedImage
;
uni
.
setStorageSync
(
'savedShareImage'
,
compressedImage
);
// this.generatedImage = imageData;
// // 将生成的图片保存到本地存储
// uni.setStorageSync('savedShareImage', imageData);
}
catch
(
error
)
{
console
.
error
(
'截图失败:'
,
error
);
throw
error
;
// 抛出错误以便外部捕获
...
...
@@ -222,7 +227,39 @@ export default {
uni
.
hideLoading
();
}
},
compressImage
(
base64
)
{
return
new
Promise
((
resolve
)
=>
{
const
img
=
new
Image
();
img
.
src
=
base64
;
img
.
onload
=
()
=>
{
const
canvas
=
document
.
createElement
(
'canvas'
);
const
ctx
=
canvas
.
getContext
(
'2d'
);
// 设置压缩后的宽高
const
maxWidth
=
800
;
const
maxHeight
=
1200
;
let
width
=
img
.
width
;
let
height
=
img
.
height
;
if
(
width
>
maxWidth
)
{
height
*=
maxWidth
/
width
;
width
=
maxWidth
;
}
if
(
height
>
maxHeight
)
{
width
*=
maxHeight
/
height
;
height
=
maxHeight
;
}
canvas
.
width
=
width
;
canvas
.
height
=
height
;
ctx
.
drawImage
(
img
,
0
,
0
,
width
,
height
);
// 降低质量
resolve
(
canvas
.
toDataURL
(
'image/jpeg'
,
0.7
));
};
});
},
saveImage
(
base64Data
)
{
// 实现保存图片到相册的逻辑
// 注意:在H5中可能需要不同的处理方式
...
...
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