前端使用js将图片转换为二进制、十六进制

javascript 复制代码
function convertImageToBinary (fileInput) {
        return new Promise((resolve, reject) => {
          const reader = new FileReader()
          reader.onloadend = function () {
            const bytes = new Uint8Array(reader.result)
            resolve(bytes)
          }
          reader.onerror = reject
          reader.readAsArrayBuffer(fileInput)
        })
      }
      convertImageToBinary(file.raw).then(res => {
        console.log('res====>', res)
        const hexValue = Array.prototype.map
          .call(res, (x) => ('0x' + x.toString(16)))
          .join('')
        console.log('hexValue=--==>', hexValue)
      })

结果:

相关推荐
Humbunklung1 小时前
Rust 控制流
开发语言·算法·rust
ghost1431 小时前
C#学习第27天:时间和日期的处理
开发语言·学习·c#
jason成都1 小时前
c#压缩与解压缩-SharpCompress
开发语言·c#
站在风口的猪11081 小时前
《前端面试题:CSS对浏览器兼容性》
前端·css·html·css3·html5
JohnYan2 小时前
Bun技术评估 - 04 HTTP Client
javascript·后端·bun
傻啦嘿哟2 小时前
从零开始:用Tkinter打造你的第一个Python桌面应用
开发语言·c#
三十一6143 小时前
6.4 C++作业
开发语言·c++
青莳吖3 小时前
使用 SseEmitter 实现 Spring Boot 后端的流式传输和前端的数据接收
前端·spring boot·后端
CodeCraft Studio3 小时前
PDF处理控件Aspose.PDF教程:在 C# 中更改 PDF 页面大小
前端·pdf·c#
我的golang之路果然有问题3 小时前
ElasticSearch+Gin+Gorm简单示例
大数据·开发语言·后端·elasticsearch·搜索引擎·golang·gin