hezi100_2017 2021-09-03 11:01 采纳率: 92.3%
浏览 194
已结题

js中如何将图片转换为二进制

例如如何将图片
imagpath: "http://124.114.179.77:6744/zhbx/image/20210903/f51c5e7cc7494f1c9ab6c606290ebb61.jpg"

转换为二进制格式呢?

  • 写回答

2条回答 默认 最新

  • 榴莲不好吃 博客专家认证 2021-09-03 11:21
    关注
    
     
    字符串转二进制:
    var arr = [], str = "http://124.114.179.77:6744/zhbx/image/20210903/f51c5e7cc7494f1c9ab6c606290ebb61.jpg";
    arr = arr.map.call(str, elem => elem.charCodeAt(0).toString(2));
    console.log(arr)
     // ["1101000", "1110100", "1110100", "1110000", "111010", "101111", "101111", "110001", "110010", "110100", "101110", "110001", "110001", "110100", "101110", "110001", "110111", "111001", "101110", "110111", "110111", "111010", "110110", "110111", "110100", "110100", "101111", "1111010", "1101000", "1100010", "1111000", "101111", "1101001", "1101101", "1100001", "1100111", "1100101", "101111", "110010", "110000", "110010", "110001", "110000", "111001", "110000", "110011", "101111", "1100110", "110101", "110001", "1100011", "110101", "1100101", "110111", "1100011", "1100011", "110111", "110100", "111001", "110100", "1100110", "110001", "1100011", "111001", "1100001", "1100010", "110110", "1100011", "110110", "110000", "110110", "110010", "111001", "110000", "1100101", "1100010", "1100010", "110110", "110001", "101110", "1101010", "1110000", "1100111"]
    二进制转字符串
    var str = arr.map(elem =>String.fromCharCode(parseInt(elem,2))).join('');
    console.log(str)
    // "http://124.114.179.77:6744/zhbx/image/20210903/f51c5e7cc7494f1c9ab6c606290ebb61.jpg"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月17日
  • 已采纳回答 9月9日
  • 创建了问题 9月3日

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题