前端使用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)
      })

结果:

相关推荐
程序员码歌1 天前
短思考第261天,浪费时间的十个低效行为,看看你中了几个?
前端·ai编程
咖啡の猫1 天前
Python字典推导式
开发语言·python
Swift社区1 天前
React Navigation 生命周期完整心智模型
前端·react.js·前端框架
若梦plus1 天前
从微信公众号&小程序的SDK剖析JSBridge
前端
leiming61 天前
C++ vector容器
开发语言·c++·算法
SystickInt1 天前
C语言 strcpy和memcpy 异同/区别
c语言·开发语言
用泥种荷花1 天前
Python环境安装
前端
CS Beginner1 天前
【C语言】windows下编译mingw版本的glew库
c语言·开发语言·windows
Light601 天前
性能提升 60%:前端性能优化终极指南
前端·性能优化·图片压缩·渲染优化·按需拆包·边缘缓存·ai 自动化
Jimmy1 天前
年终总结 - 2025 故事集
前端·后端·程序员