Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
8c6118d6
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8c6118d6
编写于
9月 24, 2019
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修复 uni.canvasToTempFilePath 参数 x、y 错误的问题 fixed #746
上级
6957475f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
47 addition
and
32 deletion
+47
-32
src/core/view/components/canvas/index.vue
src/core/view/components/canvas/index.vue
+25
-8
src/platforms/h5/service/api/context/canvas.js
src/platforms/h5/service/api/context/canvas.js
+22
-24
未找到文件。
src/core/view/components/canvas/index.vue
浏览文件 @
8c6118d6
...
...
@@ -21,6 +21,7 @@ import {
}
from
'
uni-mixins
'
import
{
pixelRatio
,
wrapper
}
from
'
uni-helpers/hidpi
'
...
...
@@ -373,10 +374,13 @@ export default {
}
},
getImageData
({
x
,
y
,
x
=
0
,
y
=
0
,
width
,
height
,
destWidth
,
destHeight
,
hidpi
=
true
,
callbackId
})
{
var
imgData
...
...
@@ -389,12 +393,25 @@ export default {
}
try
{
const
newCanvas
=
document
.
createElement
(
'
canvas
'
)
newCanvas
.
width
=
width
newCanvas
.
height
=
height
if
(
!
hidpi
)
{
if
(
!
destWidth
&&
!
destHeight
)
{
destWidth
=
Math
.
round
(
width
*
pixelRatio
)
destHeight
=
Math
.
round
(
height
*
pixelRatio
)
}
else
if
(
!
destWidth
)
{
destWidth
=
Math
.
round
(
width
/
height
*
destHeight
)
}
else
if
(
!
destHeight
)
{
destHeight
=
Math
.
round
(
height
/
width
*
destWidth
)
}
}
else
{
destWidth
=
width
destHeight
=
height
}
newCanvas
.
width
=
destWidth
newCanvas
.
height
=
destHeight
const
context
=
newCanvas
.
getContext
(
'
2d
'
)
context
.
__hidpi__
=
true
context
.
drawImageByCanvas
(
canvas
,
x
,
y
,
width
,
height
,
0
,
0
,
width
,
h
eight
,
false
)
imgData
=
context
.
getImageData
(
0
,
0
,
width
,
h
eight
)
context
.
drawImageByCanvas
(
canvas
,
x
,
y
,
width
,
height
,
0
,
0
,
destWidth
,
destH
eight
,
false
)
imgData
=
context
.
getImageData
(
0
,
0
,
destWidth
,
destH
eight
)
}
catch
(
error
)
{
UniViewJSBridge
.
publishHandler
(
'
onCanvasMethodCallback
'
,
{
callbackId
,
...
...
@@ -409,8 +426,8 @@ export default {
data
:
{
errMsg
:
'
canvasGetImageData:ok
'
,
data
:
[...
imgData
.
data
],
width
,
height
width
:
destWidth
,
height
:
destHeight
}
},
this
.
$page
.
id
)
},
...
...
src/platforms/h5/service/api/context/canvas.js
浏览文件 @
8c6118d6
import
createCallbacks
from
'
uni-helpers/callbacks
'
import
{
pixelRatio
}
from
'
uni-helpers/hidpi
'
const
canvasEventCallbacks
=
createCallbacks
(
'
canvasEvent
'
)
...
...
@@ -808,8 +807,8 @@ export function canvasPutImageData ({
}
export
function
canvasToTempFilePath
({
x
,
y
,
x
=
0
,
y
=
0
,
width
,
height
,
destWidth
,
...
...
@@ -818,13 +817,7 @@ export function canvasToTempFilePath ({
fileType
,
qualit
},
callbackId
)
{
if
(
typeof
width
!==
'
undefined
'
)
{
width
*=
pixelRatio
}
if
(
typeof
height
!==
'
undefined
'
)
{
height
*=
pixelRatio
}
var
pageId
let
pageId
const
app
=
getApp
()
if
(
app
.
$route
&&
app
.
$route
.
params
.
__id__
)
{
pageId
=
app
.
$route
.
params
.
__id__
...
...
@@ -834,37 +827,39 @@ export function canvasToTempFilePath ({
})
return
}
var
cId
=
canvasEventCallbacks
.
push
(
function
(
data
)
{
var
imgData
=
data
.
data
if
(
!
imgData
||
!
imgData
.
length
)
{
const
cId
=
canvasEventCallbacks
.
push
(
function
({
data
,
width
,
height
})
{
if
(
!
data
||
!
data
.
length
)
{
invoke
(
callbackId
,
{
errMsg
:
'
canvasToTempFilePath:fail
'
})
return
}
let
imgData
try
{
imgData
=
new
ImageData
(
new
Uint8ClampedArray
(
imgData
),
data
.
width
,
data
.
height
)
imgData
=
new
ImageData
(
new
Uint8ClampedArray
(
data
),
width
,
height
)
}
catch
(
error
)
{
invoke
(
callbackId
,
{
errMsg
:
'
canvasToTempFilePath:fail
'
})
return
}
var
canvas
=
getTempCanvas
()
canvas
.
width
=
data
.
width
canvas
.
height
=
data
.
height
var
c2d
=
canvas
.
getContext
(
'
2d
'
)
const
canvas
=
getTempCanvas
()
canvas
.
width
=
width
canvas
.
height
=
height
const
c2d
=
canvas
.
getContext
(
'
2d
'
)
c2d
.
putImageData
(
imgData
,
0
,
0
)
var
base64
=
canvas
.
toDataURL
(
'
image/png
'
)
var
img
=
new
Image
()
let
base64
=
canvas
.
toDataURL
(
'
image/png
'
)
const
img
=
new
Image
()
img
.
onload
=
function
()
{
var
width
=
canvas
.
width
=
typeof
destWidth
===
'
number
'
?
destWidth
:
imgData
.
width
*
pixelRatio
var
height
=
canvas
.
height
=
typeof
destHeight
===
'
number
'
?
destHeight
:
imgData
.
height
*
pixelRatio
if
(
fileType
===
'
jpeg
'
)
{
c2d
.
fillStyle
=
'
#fff
'
c2d
.
fillRect
(
0
,
0
,
width
,
height
)
c2d
.
fillRect
(
0
,
0
,
width
,
width
)
}
c2d
.
drawImage
(
img
,
0
,
0
,
img
.
width
,
img
.
height
,
0
,
0
,
width
,
height
)
c2d
.
drawImage
(
img
,
0
,
0
)
base64
=
canvas
.
toDataURL
(
`image/
${
fileType
}
`
,
qualit
)
invoke
(
callbackId
,
{
errMsg
:
'
canvasToTempFilePath:ok
'
,
...
...
@@ -878,6 +873,9 @@ export function canvasToTempFilePath ({
y
,
width
,
height
,
destWidth
,
destHeight
,
hidpi
:
false
,
callbackId
:
cId
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录