如何在Android上创建渐进式JPEG图像 [英] How to create a progressive JPEG image on Android
问题描述
我需要通过非常低带宽连接从Android手机(低至10kByte/s)发送图像,并希望以逐行(隔行)模式发送图像,以便在漫长的传输过程中,另一端已经开始看到图像.现在,我正在使用常规的照片应用程序来创建图像:
I need to send images over a very low-bandwidth connection from an android phone (down to 10kByte/s) and would like to send them in progressive (interlaced) mode so that the user at the other end starts seeing the image already during the lengthy transfer. Right now, I am creating the image with the regular photo app:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
但这会生成非渐进式照片,但我无法发现如何说服它去做其他事情.我探索的第二个选项(读取并重新压缩所拍摄的图像)被挫败了,因为据我所知,Bitmap的compress方法除了格式名称和压缩系数外,不允许任何编码参数:
But this creates non-progressive photos and I have not been able to discover how to convince it to do otherwise. The second option I explored (reading and re-compressing the taken image) got foiled because the Bitmap's compress method does not allow any encoding parameters besides format name and compression factor as far as I could determine:
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);
我首选的解决方案是指示照片应用以渐进模式保存.
My preferred solution would be to instruct the photo app to save in progressive mode.
下一个最佳选择是一种Java算法,该算法可以无损地将存储的jpeg转换为渐进式(jpegtran在Linux上做到了,但它在C语言中并且依赖libjepeg).
The next best option would be a Java algorithm that losslessly converts the stored jpeg to progressive (jpegtran does this on Linux, but it is in C and relies on libjepeg).
下一个最好的方法是为android指定相关编码参数的方法,以允许我重新压缩它,或者是一个替代的Java库,执行相同的操作.
The next best would a method to specify the relevant encoding parameters to android allowing me to re-compress it, or an alternative Java library that does the same.
进一步的研究表明,~/android-sdk-linux/source-tree/external/jpeg
中的算法已经存在(/system/lib/libjpeg.so
)了,但是似乎尚不存在JNI包装器.
Further research revealed that the algorithms are already there (/system/lib/libjpeg.so
) with the sources in ~/android-sdk-linux/source-tree/external/jpeg
-- but there do not seem to be JNI wrappers readily available.
推荐答案
您看过此文档吗?
http://docs. oracle.com/javase/6/docs/api/javax/imageio/plugins/jpeg/JPEGImageWriteParam.html
似乎有逐行书写支持.
或者,您可以使用例如通过JNI OpenJPEG .参见 http://www.linux-mag.com/id/7697/开始.
Alternatively, you could use e.g. OpenJPEG through JNI. See http://www.linux-mag.com/id/7697/ as a start.
这篇关于如何在Android上创建渐进式JPEG图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!