C# compression
-
I have a byte[] of jpg image of size 1.5 kb, is there any method in C# to compress this byte[] further. I tried by GZip class but actually its size has increased, i found that GZip class is unable to compress jpg image byte[]. Can anyone suggest me any more method. This is actually needed bcoz the image has to be stored i smart card application and i have limited scope to allot space. Thanx
-
I have a byte[] of jpg image of size 1.5 kb, is there any method in C# to compress this byte[] further. I tried by GZip class but actually its size has increased, i found that GZip class is unable to compress jpg image byte[]. Can anyone suggest me any more method. This is actually needed bcoz the image has to be stored i smart card application and i have limited scope to allot space. Thanx
Of course a general compression as used in ZIP can't do any better on images than the specialized JPEG compression that knows and understands what it is dealing with. If you want a smaller file, you need to throw away some of the information; here are two ideas: - reduce the number of colors - reduce the image size Yes, I know, both will reduce image quality as well. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
I have a byte[] of jpg image of size 1.5 kb, is there any method in C# to compress this byte[] further. I tried by GZip class but actually its size has increased, i found that GZip class is unable to compress jpg image byte[]. Can anyone suggest me any more method. This is actually needed bcoz the image has to be stored i smart card application and i have limited scope to allot space. Thanx
For extreme requirements like this, it may justify splitting the byte array into chunks, and using a custom compression algorithm for each chunk. For example, you may find a run of several hundred pixels with the same value, which would compress nicely with run-length encoding: The single pixel value plus a repetition factor. Other chunks may have different types of regularity you can exploit, such as a repeated block pattern. The compressed image will end up as a list of chunks, each with a byte identifier (that gives the compression type for that chunk) followed by that chunk's data. To decompress, go through the chunks, read the byte identifier, then execute the corresponding code to reconstruct that chunk.