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)
})
结果:
