2013-05-21 40 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