Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
taroMeeting
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
fengzhaoyu
taroMeeting
Commits
050f12ec
Commit
050f12ec
authored
Jan 20, 2019
by
王树冬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add poster
parent
49cfd932
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
9 deletions
+24
-9
cutter.js
src/utils/cutter.js
+24
-9
No files found.
src/utils/cutter.js
View file @
050f12ec
...
...
@@ -4,21 +4,36 @@ export default class Poster {
constructor
(
config
)
{
this
.
id
=
config
.
id
this
.
ctx
=
Taro
.
createCanvasContext
(
config
.
id
)
const
{
background
,
scale
=
1
}
=
config
const
{
background
}
=
config
this
.
scale
=
2
// 目前是写死两倍,如果想用响应式:使用前面生成的scale获取 Taro.getStorageSync('scale')
this
.
items
=
config
.
items
this
.
backgroundImage
=
background
.
image
this
.
width
=
background
.
width
this
.
height
=
background
.
height
this
.
scale
=
scale
this
.
width
=
background
.
width
*
this
.
scale
this
.
height
=
background
.
height
*
this
.
scale
// this.scale = Taro.getStorageSync('scale') || 1
}
// 背景
drawBackground
=
()
=>
{
const
w
=
this
.
width
*
this
.
scale
const
h
=
this
.
height
*
this
.
scale
this
.
ctx
.
drawImage
(
this
.
backgroundImage
,
0
,
0
,
w
,
h
)
// drawBackground = (img, x, y) => {
// const w = this.width * this.scale
// const h = this.height * this.scale
// this.ctx.drawImage(this.backgroundImage, 0, 0, w, h)
// this.ctx.save()
// }
// 背景
drawBackground
=
(
img
)
=>
{
const
w
=
this
.
width
const
h
=
this
.
height
this
.
ctx
.
drawImage
(
img
,
0
,
0
,
w
,
h
)
this
.
ctx
.
save
()
}
// 绘制图片
drawImage
=
(
img
,
x
=
0
,
y
=
0
,
width
,
height
)
=>
{
this
.
ctx
.
save
()
this
.
ctx
.
drawImage
(
img
,
x
*
this
.
scale
,
y
*
this
.
scale
,
width
*
this
.
scale
,
height
*
this
.
scale
)
this
.
ctx
.
restore
()
//恢复之前保存的绘图上下文。
}
// 圆形图
...
...
@@ -62,7 +77,7 @@ export default class Poster {
// 生成临时文件
generateTempImage
=
()
=>
{
let
num
=
1
let
num
=
2
let
destWidth
=
this
.
width
*
num
let
destHeight
=
this
.
height
*
num
Taro
.
canvasToTempFilePath
({
...
...
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