Convert Blob to binary string synchronously

前端 未结 2 1413
刺人心
刺人心 2020-12-21 02:45

I\'m trying to put image in clipboard when user copies canvas selection:

\"canvas

So I thou

2条回答
  •  囚心锁ツ
    2020-12-21 03:43

    Blob can be converted to binary string by getting Blob as dataURI and then applying atob. This, however, again [requires FileReader][3]. In my case, it's best to skip the blob alltogether:

    //Canvas to binary
    var data = atob(
      _this.editor.selection.getSelectedImage()  //Canvas
      .toDataURL("image/png")                    //Base64 URI
      .split(',')[1]                             //Base64 code
    );
    

提交回复
热议问题