压缩Base64字符串 [英] Compressing Base64 Strings

查看:655
本文介绍了压缩Base64字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿再次



我制作了一个程序,将图像转换为base64字符串并通过UDP发送。

问题是当base64太大时我得到一个错误

如何在主机端压缩它然后在客户端解压缩回base64字符串?



帮助表示赞赏。

解决方案

如果你想通过网络发送图像而你不想要TCP,因为它是'开销或其他限制,您当然可以使用UDP。但是:UDP不可靠,正如您所注意到的,如果要发送大文件(需要保持一致),可能会遇到几个问题。从理论上讲,UDP不适用于此。但现代网络可能会为您带来可以从中受益的稳定性,并实现比TCP更好的性能。但是你必须在UDP之上实现一个协议层。如果您不想考虑新的,请查看 RUDP [< a href =http://en.wikipedia.org/wiki/Reliable_User_Datagram_Protocol\"target =_ blanktitle =New Window> ^ ]。好吧,你可以自己实施,但你没有这方面的知识。所以我建议你使用这个: http://rudp.codeplex.com/ [ ^ ]。

请注意,压缩流不会帮助你,如果你试图发送已压缩的图像文件,对它的原始压缩方法完全无动于衷。 Base64编码图像并用其他方法压缩它一般会扩大结果。忘记这个想法。


为什么你首先将图像转换为Base64?当然不能认为你会得到更少的数据发送?您实际上要发送更多数据,而不是通过执行此转换。 1280x1024的屏幕截图导致刚刚超过5.12MB的数据。这个数据的Base64字符串超过6.8MB。



Base64用于发送二进制数据交叉链接和系统,仅用于承载文本流量。以太网上的UDP不是这样的传输。它将自己处理二进制数据。那么,你发送这个图像是什么,为什么它必须是Base64 ??


你好,



怎么样使用 System.IO.Compression.GZipStream 类。可以在此处找到使用此类的示例[ ^ ] MSDN库。这里还有一个例子[ ^ ]。



问候,

Hey again

I have made a program that turns an image into a base64 string and sends via UDP.
the problem is that i get an error when the base64 is too large
How do you compress this on the host side and then decompress back into a base64 string on the client side?

Help is appreciated.

解决方案

If you want to send images over network and you don''t want TCP because of it''s overhead or other limitations, you can use of course UDP. But: UDP is not reliable, and as you noticed, you might encounter several problems if you want to send large files (that need to remain consistent). Theoretically, UDP is not for that. But modern networks might bring you the stability you can benefit from, and achieve better performance than TCP. But you have to implement a layer above UDP, a protocol. If you don''t want to think about a new one, look at RUDP[^]. Well, you could implement for yourself, but you don''t have the knowledge. So I suggest you use this one: http://rudp.codeplex.com/[^].
Please note, that compressing the stream won''t help you if you try to send already compressed image files, quite indifferent of it''s original compression method. Base64 encoding an image and compressing it with an other method will in general enlarge the result. Forget this idea.


Why are you converting an image to Base64 in the first place?? Surely it can''t be to think you''ll get less data to send?? You''re actually making MORE data to send, not less by doing this conversion. A screenshot at 1280x1024 results in just over 5.12MB of data. The Base64 string of this data is over 6.8MB.

Base64 was written to send binary data acrossed links and systems designed to carry textual traffic only. UDP over Ethernet is not such a transport. It''ll handle binary data just fine on its own. So, what are you sending this image to and why does it have to be Base64??


Hello,

How about using System.IO.Compression.GZipStream class. The example of using this class can be found here[^] in MSDN library. There is one more example available here[^].

Regards,


这篇关于压缩Base64字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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