Android - 将位图图像保存在移动存储上而不压缩

Pea*_*ner 5 java android image bitmap

从远程 URL 保存位图图像的典型方法(基于研究)是:

Bitmap bmImage = null;

InputStream in = new java.net.URL(imageUrl).openStream();
bmImage = BitmapFactory.decodeStream(in);

File file = new File(myPath);

FileOutputStream outputStream;
outputStream = new FileOutputStream(file);

bmImage.compress(Bitmap.CompressFormat.PNG, 100, outputStream);

outputStream.close();
Run Code Online (Sandbox Code Playgroud)

除非压缩,否则我无法保存位图(位图始终未压缩)。远程图像大小为32KB,压缩后为110KB。我知道我必须降低压缩参数才能获得更小的尺寸,但远程图像经过优化并且效率更高。

有没有办法可以将远程图像保存在移动存储上而不压缩?

=====我的问题的答案=====

首先,我对误导性内容表示歉意;我想要的只是保存可能是 png|jpeg|gif|etc 的图像。可能我误导了你们,我试图保存的图像是 BMP 格式,但事实并非如此。

不过,对于那些想要保存图像而不压缩的人,请看看这个答案

Way*_* Jo 1

使用AndroidBmpUtil,如下代码所示:

new AndroidBmpUtil().save(bmImage, file);
Run Code Online (Sandbox Code Playgroud)

  • java.nio.BufferOverflowException 在该类中崩溃 (2认同)