public class MainActivity extends Activity { Button mButton; private static int REQ_2 = 2; private String mFilePath; ImageView mImageView; FileInputStream fileInputStream;// 输入流 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mButton = (Button) findViewById(R.id.btnCamera); mImageView = (ImageView) findViewById(R.id.ivView); mFilePath = Environment.getExternalStorageDirectory().getPath(); mFilePath = mFilePath+"/"+"temp.png"; } pubilc void cameraClick1(View view){ Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri potho = Uri.fromFile(new File(mFilePath));//指定目录 it.putExtra(MediaStore.EXTRA_OUTPUT,potho);//把系统获取到的图片放到指定的目录下 startActivityForResult(it, REQ_2); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK&&requestCode == REQ_1){ Bundle build = data.getExtras(); Bitmap bitmap = (Bitmap)build.get("data"); mImageView.setImageBitmap(bitmap); }else if(resultCode==RESULT_OK&&requestCode == REQ_2){ try { fileInputStream = new FileInputStream(mFilePath); Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream); mImageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { e.printStackTrace(); }finally { try { fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
拍照后如何得到真实大小的图片
最新推荐文章于 2019-03-18 17:19:00 发布