简体   繁体   English

串联两个base64 URL字符串(图像)

[英]Concatenating two base64 URL String (image)

so I'm trying to concatenate the two or more base64 URL string generated from my camera (using the cordova-plugin-camera ). 因此,我尝试将相机生成的两个或多个base64 URL字符串连接起来(使用cordova-plugin-camera )。 And I'm trying to generate it into one base64 URL string to convert it into a one image only. 我正在尝试将其生成为一个base64 URL字符串,以仅将其转换为一个图像。

I tried to concatenate it manually by doing this. 我试图通过这样做手动将其连接起来。

var compilation = ["data:image/jpeg;base64,"];
for(var x = 0; x < $scope.imageList.length; x++)
    compilation[0] = compilation[0] + $scope.imageList[x];

but that thing doesn't work. 但是那东西不起作用。 Any ideas how can I make this possible? 有什么想法可以使这成为可能吗?

References: 参考文献:

iOS Concatenation iOS串联

Join two Base64 strings and then decode them 连接两个Base64字符串,然后对其进行解码

Thank you! 谢谢!

Base64 encoding simply takes the bits that make up whatever it is you are encoding, in this case your images, and translates them into a string composed of a 64 character alphabet. Base64编码仅占用构成您正在编码的内容的位(在本例中为图像),并将它们转换为由64个字符的字母组成的字符串。

What you are trying to do is really no different than concatenating the original bits of the images into a single bit stream and saving it to a file. 实际上,您要做的只是将图像的原始位连接为单个位流并将其保存到文件中。 The result will be an invalid image due to image file formats having header data and stuff like that. 由于图像文件格式具有标题数据和类似内容,因此结果将是无效图像。

To top it off, base64 will add additional characters to the end of a string if the source data isn't in complete chunks of 24 bits. 最重要的是,如果源数据不是24位的完整块,base64将在字符串的末尾添加其他字符。

Here is a good break down of base64 encoding and how it works 这是对base64编码及其工作原理的一个很好的细分

To accomplish what you are trying to do, you can just use an image editor to combine the images and then base64 encode that. 要完成您想做的事情,您只需使用图像编辑器组合图像,然后对它进行base64编码。

If you want to do this programatically, you can write a simple web service that takes your 2 separate base64 encoded images and then concatenate them together in the service and then return a base64 encoded string of the new image. 如果要以编程方式执行此操作,则可以编写一个简单的Web服务,该服务将获取2个单独的base64编码图像,然后将它们串联到服务中,然后返回新图像的base64编码字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM