react-img-editor 图片编辑

react-img-editor 图片编辑,第1张

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')
  }

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/939899.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-17
下一篇2022-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存