2011-09-05 64 views

回答

1
try { 
      FileOutputStream out = new FileOutputStream(filename); 
      bmp.compress(Bitmap.CompressFormat.PNG, 90, out); 
    } catch (Exception e) { 
      e.printStackTrace(); 
    } 

從下面的函數獲取圖像並保存繪製在文件

private Drawable LoadImageFromWeb(String url) { 
    try { 
    InputStream is = (InputStream) new URL(url).getContent(); 
    Drawable d = Drawable.createFromStream(is, "src name"); 
    return d; 
    } catch (Exception e) { 
    System.out.println("Exc=" + e); 
    return null; 
    } 
} 
+0

此方法不會保存原始圖像,而是一個可以使用更多空間的重新壓縮的png。 –

6

如何從輸入流保存SD卡中的圖像..

String dir = Environment.getExternalStorageDirectory().toString(); 
OutputStream fos = null;     
File file = new File(dir,"downloadImage.JPEG"); 
Bitmap bm =BitmapFactory.decodeStream(your input stream); 
fos = new FileOutputStream(file); 
BufferedOutputStream bos = new BufferedOutputStream(fos); 
bm.compress(Bitmap.CompressFormat.JPEG, 50, bos); 
bos.flush(); 
bos.close(); 

現在你的圖像在SD卡保存爲download.JPEG ..

,您可以使用此路徑獲得的圖像..

dir+"\downloadImage.JPEG" 
相關問題