调用系统自带的拍照功能,拍摄照片,取得未经压缩的照片。
之前用PA4的 demo,取得的照片一直是压缩后的,下面的程序取得未压缩到的照片。
方法是:拍照后保存在硬盘上,之后读取文件。
P.S 需添加文件读写权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
public class MainActivity extends Activity {
private static final int TAKE_PICTURE = 0;
private ImageView image;
private Bitmap bmp;
private Uri outputFileUri;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView)findViewById(R.id.ImageView);
//set the path for image
File file = new File(Environment.getExternalStorageDirectory(),"shot.jpg");
outputFileUri = Uri.fromFile(file);
//start camera
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent,TAKE_PICTURE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == TAKE_PICTURE) {
try{
Log.i("TAG","Uri path: "+outputFileUri.getPath());
bmp = BitmapFactory.decodeFile(outputFileUri.getPath(),null);
image.setImageBitmap(bmp);
Log.i("TAG","bmp is loaded!");
}catch(Exception e){
Log.i("Tag","exception");
Log.i("Tag","Uri path: "+outputFileUri.getPath());
}
}
}
}