electron实现使用exe截屏

   const { execFile } = require('child_process');
   import axios from 'axios';
   var FormData = require('form-data');
//截屏搜索
  wxdllScreen(win){
    //  编写你的代码
    var screen_window = execFile(__static + '/wxdll/PrintScr.exe')
    screen_window.on('exit', function (code) {
      // 执行成功返回 1,返回 0 没有截图
      if (code == 1){
        //可改变图片格式,如:toJPEG
        let pngs = clipboard.readImage().toPNG()
        let imgData = Buffer.from(pngs, "beas64");
        let imgs = "data:image/png;base64," +
            btoa(new Uint8Array(imgData).reduce(
                (data, byte) => data + String.fromCharCode(byte), "")
            );
        //imgs 为base64格式
        try {
            const formData = new FormData();
            formData.append("imgFile", imgs);
            axios({
                method:'POST',
                url:`http://baidu.com`,
                data: formData,
            }).then( res => {
                let pic = res.imgurl
                if(pic){
                  win.webContents.send("screenUrl",pic)    
                }
            })
        } catch (error) {
            console.log(error);
        }
      }
    })
  },

 文中   PrintScr.exe  可在下面的链接中提取,整个文件都要

链接:https://pan.baidu.com/s/1iiRAyf-VSA864UvHX9fP-g
提取码:jzi8

posted @ 2023-11-03 11:47  江郎才尽吕小布  阅读(14)  评论(0编辑  收藏  举报