我被这个问题困扰了2天:我想压缩位图(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);
该怎么办呢。提前谢谢你抽出时间
发布于 2014-09-23 08:25:47
解码与压缩相反:它将其转换为原始像素数据。压缩对于减少存储和传输的文件大小很有用,但是当图像显示时,它会在内存中解压到与启动时相同的大小。
如果要使原始像素数据更小,则需要降低分辨率。ImgScalr库将在这里帮助您:它会产生非常好的结果。
(但我不太清楚你想要达到什么目的。)
发布于 2014-09-23 08:27:17
看这里的文件..。它可以帮助你学习其他技巧,比如减少图像的维数。
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
https://stackoverflow.com/questions/25990274
复制相似问题