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

查看:1729
本文介绍了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 /?开头?

示例:

data:image/jpeg;base64,-->/9j/<--4RYQRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAgAAAAcgEyAAIAAAAUAAAAkodpAAQAAAABAAAAqAAAANQACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKQAyMDE2OjA4OjA1IDA5OjQ1OjA4AAAAAAOgAQADAAAAAf//AACgAgAEAAAAAQAAAPGgAwAEAAAAAQAAAFkAAAAAAAAABgEDAAMAAAABAAYAAAEaAAUAAAABAAABIgEbAA....


推荐答案

Jpeg文件格式(和其他许多人一样)可以通过幻数识别。对于JPEG,幻数 ff d8 ff ,偏移 0 。如果您将此编码为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天全站免登陆