首页 > 解决方案 > 如何解码base64 fbx嵌入图像

问题描述

我有一个带有嵌入图像内容的 FBX。图片是 Base64 格式的。我读取了该块并成功解码。当图像更大时,问题就来了。FBX 将图像分成两行,看起来像 base64,但我不知道应该如何解码它。

  1. 我尝试在base64中解码这两行并在解压缩png之前将它们连接起来,但是png已损坏。
  2. 我尝试连接 Base64 字符串,但它不起作用,因为 end = trail 这种方式是错误的。
  3. 我尝试首先解压缩第一行(正确的 png,但只有图像的一半)并将第二行解压缩为位图,但由于第二行没有标题,所以是无效图像。

内容: , "iVBORw0KGgoAAAANSUhEUg...AAAAAA=", "AAAAAAAAAAAAAAAAAA...AD//wEAAP///noceab5flIAAAAAAASUVORK5CYII="

如您所见,第一行是 PNG 标头(iVBOR...),但第二行没有标头。第一行和第二行以 base64 结尾,所以我怀疑它们应该单独解码。

有人知道怎么做吗?

如何复制:打开 3ds max 创建一个平面,将图像应用为纹理,保存为带有嵌入媒体的 ascii FBX。

具有足够大小以进行拆分的 PNG

标签: imagebase64pngfbx

解决方案


I downloaded and installed the latest version of 3ds max. I created a plane and added a PNG image as a texture, I exported it as an fbx file in the (default version) ascii format using embedded media.

I saw multiple lines of base64-encoded ascii. The first line contained a PNG header and my decoder recognized it as a PNG file. Subsequent lines did not contain PNG headers and were decoded as BIN files. All of this is exactly as you describe.

However, in my case simply concatenating the decoded segments correctly regenerated the original PNG file, just as you would expect.

I used this site to decode all of the individual chunks and download them as binary files before concatenating them.

I used the open source binary editor HexEdit to examine the chunks and to concatenate them.

Since this process worked as expected, I surmise that your Base64 decoding or concatenation must be at fault. Did you write your own decoding routine? if so, perhaps you forgot to discard any bytes corresponding to padding characters (the terminal = or == used to make the final count of bytes evenly divisible by three for each line). Note that these bytes must be discarded after decoding, not before. Virtually all decoding libraries do this for you invisibly.

If this does not solve your problem, please post the PNG file you are using, the full Base64 for the first and second lines of the output, and the routine you are using to decode and concatenate them. If you do so, we will look more closely to help you sort out the problem.


推荐阅读