2012-03-08 26 views
1

我正在學習編程的android現在,我只是有幾個問題,我希望你們可以幫助我。初學者的Android開發者問題 - 相機的具體問題

1)如果我做我的程序調用攝像頭,使之能夠拍照,我想保存這些照片,我在哪裏可以使存儲程序呢?在什麼文件夾中?在assest或res文件夾中?

2)我想通過將圖像發送到服務器還可以,但我擔心的圖像尺寸將變大。無論如何,我可以壓縮圖像,使其可以更小,然後發送小版本?或者無論如何,我可以以低分辨率/質量拍攝照片?

回答

1

1)您在運行的應用程序不能訪問改變資源/資產的文件夾。您應該暫時將其寫入您的目錄中,或者您應該將其存儲在Sdcard上。

2)位圖API有壓縮給定特定的參數圖像的能力。查看SDK網站了解更多信息。

0

1)你可以存儲這些圖像到外部目錄或SD卡。

 String rootDir = Environment.getExternalStorageDirectory() 
         + File.separator + "nameofyourfolder"; 
       File rootFile = new File(rootDir); 
       rootFile.mkdir(); 
       URL url = new URL(fileURL); 

       File newFile=new File(rootFile,fileName); 
       newFile.createNewFile(); 
       FileOutputStream f = new FileOutputStream(newFile); 

       InputStream in = url.openConnection().getInputStream(); 
       byte[] buffer = new byte[1024]; 
       int len1 = 0; 
       while ((len1 = in.read(buffer)) > 0) { 
        f.write(buffer, 0, len1); 
       } 

       f.close(); 

2)可以壓縮圖片大小:

int nh = (int) (bitmap.getHeight() * (512.0/bitmap.getWidth())); 
      bitmap = Bitmap.createScaledBitmap(bitmap,512,nh,true);