嗨喽大家好,好久不见,分享一个 十六进制 转为 图片通用步骤,没多少代码,我也不详细解释了,代码中有注释。话不多说,直接上代码!
// 假设 hexString 是你的十六进制数据字符串
const hexString = "0xFFD8FFE000104A464946000101010060006000";
// 将十六进制字符串转换为 ArrayBuffer
const arrayBuffer = new Uint8Array(hexString.match(/[\da-f]{2}/gi).map(function (h) {
return parseInt(h, 16);
})).buffer;
// 创建 Blob 对象
const blob = new Blob([arrayBuffer], { type: 'image/jpeg' });
// 将 Blob 对象转换为 URL
const imageUrl = URL.createObjectURL(blob);
// 将 URL 分配给图像元素的 src 属性
const imgElement = document.querySelector('img');
imgElement.src = imageUrl;