speed up image creation / writing to byte array (SWT)
I use SWT to compress a RAW Bitmap Image to JPEG. I'm writing the image to a BufferedOut开发者_JAVA百科putStream to send the bytes over a socket. The problem is, that the compression takes a lot of time (arround 150 ms). Has anyone any suggestions to speed up the whole process?
bos.reset();
imageLoader.save(bos, SWT.IMAGE_JPEG);
One possibility is to send the images uncompressed. If your effective network throughput rate is high enough, it could take longer to compress the images than to send them.
Another possibility is to pipeline the process, so that you are sending one image at the same time as you are compressing the next one. If you have multiple cores, it may be worth using multiple threads to do the compression.
FOLLOWUP
If compression is essential, you are probably best sticking with JPEG. However, you should be aware that JPEG compression is lossy, and the details that you lose can never be recovered. (By contrast, the deflater that you tried would have been lossless.)
精彩评论