base64 格式的 JPEG 图像 [英] JPEG image in base64 format

查看:68
本文介绍了base64 格式的 JPEG 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台相机,它向我发送一个带有一些标签的 xml 文件,其中包括一个以 base64 格式表示图像的标签.图片为JPEG格式.

I have a camera that send me an xml file with some tags , including a tag that represents the image in base64 format. The image is in JPEG format.

由于某种原因,代表图像的标签并不总是具有相同的名称(由于相机问题)

For some reason the tag that represents the image it doesn't always have the same name (for a problem of the camera)

所以要确定地检测包含图像的标签是正确的,我现在必须做一件事:

So to detect with certainty the tag that contains the image is correct i have to now one thing :

base64 格式的 JPEG 图像总是以/9j/开头?

例子:

<代码>数据:图像/JPEG; BASE64, - >/9J/< - 4RYQRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAgAAAAcgEyAAIAAAAUAAAAkodpAAQAAAABAAAAqAAAANQACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKQAyMDE2OjA4OjA1IDA5OjQ1OjA4AAAAAAOgAQADAAAAAf//AACgAgAEAAAAAQAAAPGgAwAEAAAAAQAAAFkAAAAAAAAABgEDAAMAAAABAAYAAAEaAAUAAAABAAABIgEbAA ....

推荐答案

Jpeg 文件格式(和许多其他格式一样)可以通过幻数来识别.对于 JPEG,幻数是偏移量 0 处的 ff d8 ff.如果将其编码为 Base64,您将始终得到 /9j/.

Jpeg file format (as many others) can be identified by magic number. For JPEG the magic number is ff d8 ff at offset 0. If you encode this to Base64, you'll always get /9j/.

附加说明:由于 Base64 将 3 个数据字节组转换为 4 个字节 (ASCII),这将适用于长度和偏移量为 3 个字节的倍数的任何幻数.如果幻数的长度不是 3 的倍数,则最后一组 4 个 Base-64 编码字符将根据紧随幻数的数据而变化.

Additional note: since Base64 converts group of 3 data bytes to 4 bytes (ASCII), this will work for any magic number with length and offset multiple of 3 bytes. If the length of magic number is not multiple of 3, the last group of 4 Base-64 encoded characters will change depending on the data immediately following the magic number.

https://en.wikipedia.org/wiki/JPEG

https://en.wikipedia.org/wiki/List_of_file_signatures

这篇关于base64 格式的 JPEG 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆