2013-05-21 39 views
0

按下捕獲Button後,圖像應該保存在SD卡中,它正在拍攝快照但不保存圖像, 那麼我怎麼能把捕獲按鈕放在我想要的地方?我在Imageview中覆蓋了一層,我需要將該按鈕放在覆蓋層上。Android Image未保存到SD卡

+0

你有WRITE_EXTERNAL_STORAGE權限嗎?/SD卡/圖像退出您的SD卡? – Blackbelt

+0

是的,我在清單中有這個。 – Aaloka

回答

1

用這個存儲圖像SD卡

 public void save(Bitmap image) 
        { 
      File sdcard = Environment.getExternalStorageDirectory(); 
      File f = new File (sdcard, imagename); 
      FileOutputStream out=null; 
      try { 
       out = new FileOutputStream(f); 
      } catch (FileNotFoundException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      image.compress(Bitmap.CompressFormat.PNG, 90, out); 
      try { 
       out.flush(); 
       out.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
} 
1

INT圖片回調,這樣使用

jpegCallback = new PictureCallback() { 
     public void onPictureTaken(byte[] data, Camera camera) { 
      camera.startPreview(); 
      FileOutputStream outStream = null; 
      try { 
       outStream = new FileOutputStream(
         "/mnt/sdcard/myphoto.jpg"); 
       outStream.write(data); 
       outStream.close(); 
       Log.d("Log", "onPictureTaken - wrote bytes: " + data.length); 
      } catch (FileNotFoundException e) { 
       e.printStackTrace(); 

      } catch (IOException e) { 
       e.printStackTrace(); 
      } finally { 

      } 
      Log.d("Log", "onPictureTaken - jpeg"); 
     } 
    }; 
0
stream=new ByteArrayOutputStream(); 
temBitmap=Bitmap.createBitmap(bmp); 
temBitmap.compress(Bitmap.CompressFormat.JPEG,100, stream); 
path+=String.format(
       getString(R.string._sdcard_d_jpg), 
       System.currentTimeMillis()); 
    outStream = new FileOutputStream(path+extension); // <9> 
    outStream.write(stream.toByteArray()); 
    outStream.close(); 

改變上面的代碼是這樣的:

path+=String.format(
      getString(R.string._sdcard_d_jpg), 
      System.currentTimeMillis()); 
    outStream = new FileOutputStream(path+extension); // <9> 
    temBitmap=Bitmap.createBitmap(bmp); 
    temBitmap.compress(Bitmap.CompressFormat.JPEG,100, outStream); 
    outStream.close();  
    temBitmap.recycle() 
+0

那麼如果沒有這個outStream.write(stream.toByteArray()),如何可以寫入SD卡? ? – Aaloka

+0

你爲什麼需要? Bitmap.compresss不會寫入 – Blackbelt

+0

不起作用。 :( – Aaloka