Camera应用程序在清单文件中指定了以下意图过滤器。
<intent-filter> <action android:name="android.media.action.IMAGE_CAPTURE"/> <category android:name="android.intent.category.DEFAULT"> </intent-filter>通过startActivityForResult方法,允许我们访问从Camera应用程序中返回的数据,以位图(Bitmap)形式捕获的图像。 代码参考如下:
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(i, 0); -------- protected void onActivityResult(int requestCode, int resultCode, Intent intent){ super.onActrivityResult(requestCode, resultCode, intent); if(requestCode == RESULT_OK){ // get the bitmap Bundle extras = intent.getExtras(); Bitmap bmp = (Bitmap) extras.get("data"); // use the bitmap mImageView.setImageBitmap(bmp); } }注意点: 1.使用MediaStore类中的常量ACTION_IMAGE_PICTURE, 而不要直接使用“android.media.action.IMAGE_CAPTURE”, 使用常量更能适应未来的变化。 2.返回的图像可能较小,可根据具体机器进行调试修改。
获取到大图后,需要优化加载Bitmap,不然可能出现大图加载内存溢出的问题,请参考我的另一篇文章: Android Bitmap在不加载图片的前提获取宽高