加速图像创建/写入字节数组(SWT)
我使用 SWT 将 RAW 位图图像压缩为 JPEG。我将图像写入 BufferedOutputStream 以通过套接字发送字节。问题是,压缩需要很长时间(大约 150 毫秒)。有人有任何加快整个过程的建议吗?
bos.reset();
imageLoader.save(bos, SWT.IMAGE_JPEG);
I use SWT to compress a RAW Bitmap Image to JPEG. I'm writing the image to a BufferedOutputStream 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种可能性是发送未压缩的图像。如果您的有效网络吞吐率足够高,则压缩图像可能比发送图像花费更长的时间。
另一种可能性是管道化该过程,以便您在压缩下一个图像的同时发送一个图像。如果您有多个核心,则可能值得使用多个线程来进行压缩。
后续
如果压缩至关重要,那么您最好坚持使用 JPEG。但是,您应该意识到 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.)