提交 ab3dfc2c 编写于 作者: H hdx

canvas: canvasToBlob 仅web可见

上级 25834287
<template> <template>
<view class="page" id="page-canvas"> <view class="page" id="page-canvas">
<canvas id="canvas" class="canvas-element"></canvas> <canvas id="canvas" class="canvas-element"></canvas>
<scroll-view class="scroll-view"> <scroll-view class="scroll-view">
<!-- #ifdef WEB -->
<button class="canvas-drawing-button" @click="canvasToBlob">canvasToBlob</button> <button class="canvas-drawing-button" @click="canvasToBlob">canvasToBlob</button>
<!-- #endif -->
<button class="canvas-drawing-button" @click="canvasToDataURL">canvasToDataURL</button> <button class="canvas-drawing-button" @click="canvasToDataURL">canvasToDataURL</button>
<text>{{dataBase64}}</text> <text>{{dataBase64}}</text>
</scroll-view> </scroll-view>
...@@ -49,13 +51,13 @@ ...@@ -49,13 +51,13 @@
this.canvas = canvas; this.canvas = canvas;
}, },
methods: { methods: {
// #ifdef WEB
canvasToBlob() { canvasToBlob() {
// #ifdef WEB
this.canvas!.toBlob((blob : Blob) => { this.canvas!.toBlob((blob : Blob) => {
this.testToBlobResult = (blob.size > 0 && blob.type == 'image/jpeg') this.testToBlobResult = (blob.size > 0 && blob.type == 'image/jpeg')
}, 'image/jpeg', 0.95) }, 'image/jpeg', 0.95)
// #endif
}, },
// #endif
canvasToDataURL() { canvasToDataURL() {
this.dataBase64 = this.canvas!.toDataURL() this.dataBase64 = this.canvas!.toDataURL()
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册