【发布时间】:2013-04-21 15:51:55
【问题描述】:
我可以通过以下意图拍照
cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
然后在onActivityResult 方法中,我将拍摄的图像设置为ImageView,并尝试使用以下函数将图像存储到 SD 卡中
private void savePic(Bitmap bmp) {
if(!isSDOK || !isSDWritable)
return;
String name = "TESTA";
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(path,name+".jpg");
path.mkdirs();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 100 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(bitmapdata);
try{
InputStream is = bis;
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read();
os.write(data);
is.close();
os.close();
}catch(Exception e){Log.e("IMAGE CONVERT ERR", e.toString());}
return;
}
当我检查PICTURES 文件夹时,我看到了文件,但图像是空白的,并且大小始终为 12kb。我不能用我上面的方法从位图文件中保存图像吗?
【问题讨论】:
-
为什么不把
EXTRA_OUTPUT放在Intent上,这样第三方相机应用就可以为您存储图像?
标签: android android-camera android-camera-intent