Android调用系统相机 并返回原始图片
2016-06-13 本文已影响1508人
Allen_han
//获取SD卡路径
mFilePath= Environment.getExternalStorageDirectory().getPath();
mFilePath=mFilePath+"/"+ String.valueOf(System.currentTimeMillis()) +".jpg";
//指定拍照
Intent intent =newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
//加载路径
Uri uri = Uri.fromFile(newFile(mFilePath));
//指定存储路径,这样就可以保存原图了
intent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
//拍照返回图片
startActivityForResult(intent,2);
if(requestCode ==2) {
String filePath=mFilePath;
Bitmap bitmap=BitmapFactory.decodeFile(filePath,getBitmapOption(2));//将图片的长和宽缩小味原来的1/2
imageViews.setImageBitmap(bitmap);
}
private BitmapFactory.Options getBitmapOption(int inSampleSize){
System.gc();
BitmapFactory.Options options =newBitmapFactory.Options();
options.inPurgeable=true;
options.inSampleSize= inSampleSize;
returnoptions;
}