
demo:
npm install react-img-editor -S
引入和使用
import ReactImgEditor from 'react-img-editor'
import 'react-img-editor/assets/index.css'
保存:
const stageRef = useRef(null)
const setStage = (stage) => {
stageRef.current = stage
}
// 保存
const save = () => {
const canvas = stageRef.current.clearAndToCanvas({ pixelRatio: stageRef.current._pixelRatio })
canvas.toBlob(function (blob: any) {
const fileReader = new FileReader();
fileReader.onload = async (e: any) => {
console.log(e.target.result)//base64
};
fileReader.readAsDataURL(blob);
fileReader.onerror = () => {
};
}, 'image/jpeg')
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)