2017-02-07 25 views
0

我不想使用位图的压缩方法。我只是想直接写入SD卡。不想在我的情况下使用压缩。如何在没有bitmap.compress方法的情况下将位图写入文件

+0

最常见的图像格式是自然压缩的(例如,PNG,JPEG,WebP)。你想要使用什么**特定的**图像格式? – CommonsWare

+0

我想在PNG本身的图像,但不希望减少其大小或分辨率的方法。将文件另存为原件。 –

+1

“不希望减小其大小或分辨率的方法” - compress()不会更改分辨率。 “将文件保存为原始文件” - 因为您没有提供[mcve]来证明“原始文件”来自哪里,并且由于您没有通过“将文件另存为原件”来定义您的意思,因此很难任何人都可以帮助你。 – CommonsWare

回答

1

基于标题:这会直接保存文件网址:

FileOutputStream output = ctx.openFileOutput(localFileName, context.MODE_PRIVATE); 

      URLConnection openConnection = new URL(url).openConnection(); 
      openConnection.connect(); 
      InputStream inputStream = openConnection.getInputStream(); 
      byte[] buffer = new byte[1024]; 
      for (int n = inputStream.read(buffer); n >= 0; n = inputStream.read(buffer)) 
       output.write(buffer, 0, n); 
      output.flush(); 
      output.close(); 
      inputStream.close(); 

您可以更改openFileOutput新FileOutputStream中(新文件(“文件路径”))存储在SD卡

但是你看起来像是有ImageLoader API的问题。

+0

索引1024是否足够用于任何图像文件大小? –

+0

该buff用于inputStream.read。围绕这个数字可以找到许多讨论,但我们通常使用1024或2048. http://stackoverflow.com/questions/8748960/how-do-you-decide-what-byte-size-to-use-for-inputstream -read –

+0

作品像魅力! –

相关问题