我想用相机拍摄图像并将其保存到图片文件夹中...我唯一无法解决的问题是为什么我的图像以小尺寸保存...
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, TAKE_PICTURE);
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturned) {
super.onActivityResult(requestCode, resultCode, imageReturned);
switch(requestCode) {
case TAKE_PICTURE:
if(resultCode == RESULT_OK)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 100, bytes);
File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+ File.separator + "test3.png");
try {
f.createNewFile();
//write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.flush();
// remember close de FileOutput
fo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
1 回答
您应该考虑阅读文档:
http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE
它总是会给你一个较小的图像,除非你设置它给你全尺寸:
直接来自开发网站