如何缩小BufferedImage的大小和质量? [英] How to scale down the size and quality of an BufferedImage?

查看:902
本文介绍了如何缩小BufferedImage的大小和质量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目上,一个名为远程桌面控件"的客户端-服务器应用程序.我需要做的是捕获客户端计算机的屏幕截图,并将此屏幕截图发送到服务器计算机.我可能需要每秒发送3到5张图像.但是考虑到直接发送BufferedImage对于该过程而言代价太高,因此我需要减小图像的大小.图像质量不必损失得更少.

I'm working on a project, a client-server application named 'remote desktop control'. What I need to do is take a screen capture of the client computer and send this screen capture to the server computer. I would probably need to send 3 to 5 images per second. But considering that sending BufferedImage directly will be too costly for the process, I need to reduce the size of the images. The image quality need not to be loss less.

如何减小图像的字节大小?有什么建议吗?

How can I reduce the byte size of the image? Any suggestions?

推荐答案

您可以使用

You can compress it with ZIP very easily by using GZIPInputStream and its output counterpart on the other end of the socket.

还请注意,您可以创建用于传输的 delta 图像,例如,可以使用透明色"(魔术粉红色#FF00FF)来指示在屏幕的该部分未进行任何更改.另一方面,您可以在最后一个图像上绘制新图像,而忽略这些魔术像素.

Also note that you can create delta images for transmission, you can use a "transpartent color" for example (magic pink #FF00FF) to indicate that no change was made on that part of the screen. On the other side you can draw the new image over the last one ignoring these magic pixels.

请注意,如果图片已经包含此颜色,则可以将实际的粉红色像素更改为例如#FF00FE.这是不明显的.

Note that if the picture already contains this color you can change the real pink pixels to #FF00FE for example. This is unnoticable.

另一种选择是在每个图像上传输一个 1位掩码(在将不变像素绘制为任意颜色之后.为此,您可以更改通常用于图片以产生最佳压缩率(最佳霍夫曼编码).

An other option is to transmit a 1-bit mask with every image (after painting the no-change pixels to an arbitrary color. For this you can change the color which is mostly used in the picture to result in the best compression ratio (optimal huffman-coding).

这篇关于如何缩小BufferedImage的大小和质量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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