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

结果:

相关推荐
Whisper_Sy19 小时前
Flutter for OpenHarmony移动数据使用监管助手App实战 - 应用列表实现
android·开发语言·javascript·flutter·php
小CC吃豆子19 小时前
Python爬虫
开发语言·python
机器视觉知识推荐、就业指导19 小时前
Qt 6 所有 QML 类型(官方完整清单 · 原始索引版)
开发语言·qt
json{shen:"jing"}20 小时前
1. 两数之和
前端·javascript·数据库
techdashen20 小时前
Rust OnceCell 深度解析:延迟初始化的优雅解决方案
开发语言·oracle·rust
github.com/starRTC20 小时前
Claude Code中英文系列教程19:使用subagent子代理与创建自定义子代理【重要】
前端·javascript·数据库
少控科技20 小时前
QT新手日记033
开发语言·qt
hua_ban_yu20 小时前
vue3 + ts 制作指令,防止按钮在固定时间内重复点击,不会影响到表单的校验
前端·javascript·vue.js
老神在在00120 小时前
Token身份验证完整流程
java·前端·后端·学习·java-ee
王九思20 小时前
Java 内存分析工具 MAT
java·开发语言·安全