2012-02-20 68 views
2

我尝试下面的代码,以获得一个URL文件的缩略图。图像的保存字节数组到文件

MediaMetadataRetriever mmr = new MediaMetadataRetriever(); 
mmr.setDataSource(URL); 
byte[] image = mmr.getEmbeddedPicture(); 

我得到了缩略图的字节数组(图像)。 我想将它保存为图像文件。 我该怎么办?

回答

14

你可以试试这个。

public writeToFile(byte[] array) { 
    try { 
     String path = "..."; 
     FileOutputStream stream = new FileOutputStream(path); 
     stream.write(array); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 
} 
+1

不应该是IOException同时捕获FileOutputStream和write()? – 2017-08-25 21:45:51