Compress images or strings.

Oct 19, 2009 at 12:35 PM

Just wondering if there are any methods which can be used for compressing images such as emf/wmf file and strings.

Thanks

N

Coordinator
Oct 19, 2009 at 6:59 PM
Edited Oct 19, 2009 at 7:04 PM

Yes, for example there are CompressString and CompressBuffer methods on each of the GZipStream, DeflateStream, and ZlibStream classes in the Ionic.Zlib namespace within DotNetZip.  Links to the doc:

ZlibStream.CompressString
ZlibStream.CompressBuffer
GZipStream.CompressString
GZipStream.CompressBuffer
DeflateStream.CompressString
DeflateStream.CompressBuffer

What's the scenario?

 

Oct 23, 2009 at 10:15 AM

Hi Cheeso

Here is the scenario:

I have a string which is converted to Base64string and i am trying to send it via a webservice to a client.

Will anyone of the above methods be ok or is there a preferred one.

Thanks

N

Coordinator
Oct 23, 2009 at 1:44 PM
Edited Oct 25, 2009 at 2:06 PM

hmmm,  "a string converted to a base64string"?     A base64string is a base64 string-encoded version of a byte array, right?   It is normally used as a mechanism for encoding of binary data, so that it can be transmitted as text, say... in a webservices call.  

You cannot, therefore, compress a base64string.  Well you can, but it doesn't make sense to do so.   What you get from compressing a base64string is a byte array, which then needs to be encoded into a string again.  Which is likely just as large as the original.  You see, it doesn't make sense to do it in that order.

I think what you may want to do is compress the byte array *before* it is encoded as a base64string.   When you compress a byte array, you get... a smaller byte array.  then when encoded for transmission it becomes a base64string, as in the original, uncompressed version of things, but smaller than the original base64string.

Any of those methods will work just fine.  The DeflateStream will produce the smallest result.

Good luck.