Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android JPEG压缩与原始图像大小相同_Android_Bitmap_Compression - Fatal编程技术网

Android JPEG压缩与原始图像大小相同

Android JPEG压缩与原始图像大小相同,android,bitmap,compression,Android,Bitmap,Compression,我被这个问题困扰了两天: 我想压缩位图(JPEG) 我在这里和谷歌上找到了一些有用的信息,但没有一个有用 我的JPEG文件在资源中。我可以毫无问题地阅读,检索所有信息。 当我压缩它时,我的byte[]数组很好,但使用decodeByteArray时,大小与原始数组相同 这是密码 InputStream in = assets.open(fileName); Config config = Bitmap.Config.RGB_565; Options options = new Options

我被这个问题困扰了两天: 我想压缩位图(JPEG)

我在这里和谷歌上找到了一些有用的信息,但没有一个有用

我的JPEG文件在资源中。我可以毫无问题地阅读,检索所有信息。 当我压缩它时,我的byte[]数组很好,但使用decodeByteArray时,大小与原始数组相同

这是密码

InputStream in = assets.open(fileName);


Config config = Bitmap.Config.RGB_565;
Options options = new Options();

options.inPreferredConfig = config;

Bitmap bitmap = BitmapFactory.decodeStream(in, null, options);

ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
bitmap  = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()),null,options);
我不知道该怎么办。
提前感谢您的时间

解码与压缩相反:它将压缩转换为原始像素数据。压缩对于减少存储和传输的文件大小很有用,但当图像显示时,它会在内存中解压缩到与启动时相同的大小

如果要使原始像素数据更小,则需要降低分辨率。ImgScalr库将在这方面帮助您:它产生非常好的结果


(但我不太确定你想要达到什么目的。)

看看这里的文档。。它可以帮助你在其他方面,如减少图像的尺寸


`我想压缩位图(JPEG)。`??位图不是jpeg。这是什么意思?对不起,我的位图是从资源中的JPEG文件(不是PNG)加载的(据我所知,PNG无法压缩,我认为有必要提及源文件是jpeg。奇怪的是,生成的文件大小将完全等于原始文件大小(以字节为单位)。您使用压缩质量50,这将减少文件大小。尝试使用15。压缩jpeg没有多大意义,除非您承担质量损失。+1对于我来说mgScalr。以下是maven存储库中最新版本(4.2)的链接: