Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
take_order
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
和慭琛
take_order
Commits
3e6c8074
Commit
3e6c8074
authored
Dec 30, 2020
by
和慭琛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
拍照处理方法梳理
parent
772e5c8b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
127 deletions
+101
-127
try.vue
take-order/pages/photo/try.vue
+101
-127
No files found.
take-order/pages/photo/try.vue
View file @
3e6c8074
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
<cover-image
class=
"backIcon"
:src=
"icon_arrow_down"
mode=
""
@
click=
"backClick"
></cover-image>
<cover-image
class=
"backIcon"
:src=
"icon_arrow_down"
mode=
""
@
click=
"backClick"
></cover-image>
<!--cover-image class='flashIcon' :src='icon_light_on_white' @click="flashClick()">
</cover-image-->
<!--cover-image class='flashIcon' :src='icon_light_on_white' @click="flashClick()">
</cover-image-->
</cover-view>
</cover-view>
<
!--canvas class="showCanvas" v-show='showImage' canvas-id="canvas">
</canvas--
>
<
canvas
v-show=
'showImage'
canvas-id=
"canvas"
:style=
"
{'width':width,'height': height}">
</canvas
>
</view>
</view>
...
@@ -46,6 +46,8 @@
...
@@ -46,6 +46,8 @@
liveWaterMarkImage
:
'/static/live_mark.png'
,
liveWaterMarkImage
:
'/static/live_mark.png'
,
icon_arrow_down
:
'https://qn-static.banshouhui.com/arrow_down.png'
,
icon_arrow_down
:
'https://qn-static.banshouhui.com/arrow_down.png'
,
icon_live_mark
:
'https://qn-static.banshouhui.com/live_mark.png'
,
icon_live_mark
:
'https://qn-static.banshouhui.com/live_mark.png'
,
width
:
''
,
height
:
''
,
}
}
},
},
onLoad
(
e
)
{
onLoad
(
e
)
{
...
@@ -88,33 +90,110 @@
...
@@ -88,33 +90,110 @@
});
});
},
},
//拍照
//
第一步:
拍照
takePhoto
(){
takePhoto
(){
let
that
=
this
this
.
ctx
.
takePhoto
({
this
.
ctx
.
takePhoto
({
quality
:
'high'
,
quality
:
'high'
,
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
console
.
log
(
'拍照成功'
)
console
.
log
(
'拍照成功'
)
console
.
log
(
res
)
console
.
log
(
res
)
this
.
imageChange
(
res
)
//this.getImageInfo(res.tempImagePath)
//this.imageChange(res)
this
.
getImageInfo
(
res
.
tempImagePath
)
//this.saveToLocal(res.tempImagePath)
//this.saveToLocal(res.tempImagePath)
}
}
});
});
},
},
//获取图片信息
//第二步: 获取图片信息
getImageInfo
(
tempImagePath
)
{
getImageInfo
(
tempImagePath
)
{
let
that
=
this
let
that
=
this
uni
.
getImageInfo
({
uni
.
getImageInfo
({
src
:
tempImagePath
,
src
:
tempImagePath
,
success
(
res
)
{
success
(
res
)
{
console
.
log
(
'获取图片信息成功'
)
//that.saveToLocal(res.)
//that.saveToLocal(res.)
that
.
width
=
res
.
width
/
3
+
'px'
;
that
.
height
=
res
.
height
/
3
+
'px'
;
that
.
drawCanvas
(
tempImagePath
,
res
)
}
}
})
})
},
},
//保存到本地相册
//第三步: 绘制画布
drawCanvas
:
function
(
tempImagePath
,
res
){
console
.
log
(
'绘制画布'
)
this
.
showImage
=
true
//将原图画到canvas上面
this
.
canvas
=
uni
.
createCanvasContext
(
"canvas"
,
this
)
this
.
canvas
.
drawImage
(
tempImagePath
,
0
,
0
,
res
.
width
/
3
,
res
.
height
/
3
)
this
.
canvas
.
draw
()
uni
.
showLoading
({
title
:
'数据处理中...'
,
icon
:
'loading'
,
duration
:
10000
})
//that.canvas.draw()
this
.
exportCanvasTempFilePath
(
res
.
width
,
res
.
height
)
},
//第四步: 导出画布
exportCanvasTempFilePath
:
function
(
width
,
height
){
console
.
log
(
'导出画布'
)
console
.
log
(
'width:'
+
width
)
console
.
log
(
'height:'
+
height
)
let
that
=
this
//导出自己需要的图片
uni
.
canvasToTempFilePath
({
canvasId
:
"canvas"
,
success
:
function
(
ress
)
{
that
.
image
=
ress
.
tempFilePath
//处理好的图片
uni
.
hideLoading
()
console
.
log
(
'处理图片 成功:'
)
console
.
log
(
ress
.
tempFilePath
)
uni
.
showToast
({
icon
:
'none'
,
title
:
'处理成功'
})
setTimeout
(
function
()
{
that
.
saveToLocal
(
ress
.
tempFilePath
)
uni
.
previewImage
({
urls
:
[
ress
.
tempFilePath
],
current
:
0
});
},
1000
);
//TODO........
},
fail
:
function
(
e
)
{
uni
.
hideLoading
()
uni
.
showToast
({
title
:
'出错啦...'
,
icon
:
'loading'
})
console
.
log
(
'处理图片 失败:'
)
console
.
log
(
e
)
}
});
},
//第五步: 保存到本地相册
saveToLocal
(
tempImagePath
)
{
saveToLocal
(
tempImagePath
)
{
uni
.
saveImageToPhotosAlbum
({
uni
.
saveImageToPhotosAlbum
({
filePath
:
tempImagePath
,
filePath
:
tempImagePath
,
...
@@ -127,130 +206,25 @@
...
@@ -127,130 +206,25 @@
})
})
},
},
//照片处理
//获取当前时间
imageChange
(
options
)
{
getTime
:
function
(){
var
that
=
this
//原图片信息
var
date
=
new
Date
(),
var
_width
=
options
.
width
year
=
date
.
getFullYear
(),
var
_height
=
options
.
height
month
=
date
.
getMonth
()
+
1
,
that
.
path
=
options
.
tempImagePath
day
=
date
.
getDate
(),
console
.
log
(
'原照片信息'
)
hour
=
date
.
getHours
()
<
10
?
"0"
+
date
.
getHours
()
:
date
.
getHours
(),
console
.
log
(
'宽:'
+
options
.
width
)
minute
=
date
.
getMinutes
()
<
10
?
"0"
+
date
.
getMinutes
()
:
date
.
getMinutes
(),
console
.
log
(
'高:'
+
options
.
height
)
second
=
date
.
getSeconds
()
<
10
?
"0"
+
date
.
getSeconds
()
:
date
.
getSeconds
();
console
.
log
(
'路径:'
+
options
.
tempImagePath
)
month
>=
1
&&
month
<=
9
?
(
month
=
"0"
+
month
)
:
""
;
day
>=
0
&&
day
<=
9
?
(
day
=
"0"
+
day
)
:
""
;
//需要的图片信息
var
timer
=
year
+
'/'
+
month
+
'/'
+
day
+
' '
+
hour
+
':'
+
minute
+
':'
+
second
;
var
image_x
=
parseInt
(
_width
*
0.1
);
return
timer
;
var
image_y
=
parseInt
(
_height
*
0.09
);
},
var
image_width
=
parseInt
(
_width
*
0.8
);
var
image_height
=
parseInt
(
_height
*
0.87
);
console
.
log
(
'需要的图片信息'
)
console
.
log
(
'x:'
+
image_x
)
console
.
log
(
'y:'
+
image_y
)
console
.
log
(
'宽:'
+
image_width
)
console
.
log
(
'高:'
+
image_height
)
uni
.
getImageInfo
({
src
:
that
.
path
,
success
:
function
(
res
)
{
that
.
showImage
=
true
//将原图画到canvas上面
that
.
canvas
=
uni
.
createCanvasContext
(
"canvas"
,
that
)
//that.canvas.drawImage(that.path, 0, 0, _width, _height)
that
.
canvas
.
drawImage
(
that
.
path
,
0
,
0
,
res
.
width
*
3
,
res
.
height
*
3
)
/*
//-----------------------------
// let ctx = uni.createCanvasContext('firstCanvas'); // 创建画布
// //将图片src放到cancas内,宽高为图片大小
// ctx.drawImage(res.tempFilePaths[0], 0, 0, ress.width / 3, ress.height / 3)
that.canvas.setFontSize(18)
// that.canvas.setFillStyle('#8a2929')
// that.canvas.rotate(-Math.PI / 2);
let textToWidth = res.width / 3 * 0.5;
let textToHeight = res.height / 3 * 0.3;
that.canvas.fillText('我是水印', 10, 90)
//. 除了上面的文字水印,这里也可以加入图片水印
// ctx.drawImage('/static/watermark.png', 0, 0, res.width / 3, ress.height / 3)
that.canvas.drawImage('/static/live_mark.png', 0, 0, 200, 200)
//-----------------------------
*/
that
.
canvas
.
draw
()
uni
.
showLoading
({
title
:
'数据处理中...'
,
icon
:
'loading'
,
duration
:
10000
})
that
.
canvas
.
draw
()
setTimeout
(
function
()
{
//导出自己需要的图片
uni
.
canvasToTempFilePath
({
canvasId
:
"canvas"
,
x
:
image_x
,
y
:
image_y
,
width
:
image_width
,
height
:
image_height
,
destWidth
:
image_width
,
destHeight
:
image_height
,
success
:
function
(
ress
)
{
that
.
image
=
ress
.
tempFilePath
//处理好的图片
uni
.
hideLoading
()
console
.
log
(
'处理图片 成功:'
)
console
.
log
(
ress
.
tempFilePath
)
uni
.
showToast
({
icon
:
'none'
,
title
:
'处理成功'
})
setTimeout
(
function
()
{
that
.
saveToLocal
(
ress
.
tempFilePath
)
uni
.
previewImage
({
urls
:
[
ress
.
tempFilePath
],
current
:
0
});
// uni.navigateTo({
// url:'/pages/photo/preview'+'?path=' + res.tempFilePath
// })
},
1000
);
//TODO........
},
fail
:
function
(
e
)
{
uni
.
hideLoading
()
uni
.
showToast
({
title
:
'出错啦...'
,
icon
:
'loading'
})
console
.
log
(
'处理图片 失败:'
)
console
.
log
(
e
)
}
});
},
1000
);
}
})
},
//获取当前时间
getTime
:
function
(){
var
date
=
new
Date
(),
year
=
date
.
getFullYear
(),
month
=
date
.
getMonth
()
+
1
,
day
=
date
.
getDate
(),
hour
=
date
.
getHours
()
<
10
?
"0"
+
date
.
getHours
()
:
date
.
getHours
(),
minute
=
date
.
getMinutes
()
<
10
?
"0"
+
date
.
getMinutes
()
:
date
.
getMinutes
(),
second
=
date
.
getSeconds
()
<
10
?
"0"
+
date
.
getSeconds
()
:
date
.
getSeconds
();
month
>=
1
&&
month
<=
9
?
(
month
=
"0"
+
month
)
:
""
;
day
>=
0
&&
day
<=
9
?
(
day
=
"0"
+
day
)
:
""
;
var
timer
=
year
+
'/'
+
month
+
'/'
+
day
+
' '
+
hour
+
':'
+
minute
+
':'
+
second
;
return
timer
;
},
...
...
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