Android菜鸟笔记-调用相机拍照后返回照片过小的问题

最近通过Intent调用系统相机拍照后,发现返回的照片像素变小,照片质量也变低,上网搜索后问题得到解决,感谢那位高人。

代码如下:

1.调用系统相机进行拍照

String SD_CARD_TEMP_DIR="/mnt/sdcard/"+"tem.jpg";
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(SD_CARD_TEMP_DIR)));
startActivityForResult(intent,10);//requestCode:10,任意(If >= 0, this code will be returned in onActivityResult() when the activity exits.) 


2.覆写onActivityResult(),用来处理返回的数据

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
			String sdStatus = Environment.getExternalStorageState();
			if(!sdStatus.equals(Environment.MEDIA_MOUNTED))
			{
				return;
			}
			  ContentResolver resolver = getContentResolver();
		        try {
		            File f = new File(SD_CARD_TEMP_DIR);
		            try {
		                Uri capturedImage = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(
		                        getContentResolver(), f.getAbsolutePath(), null, null));
		                // 将图片内容解析成字节数组
		                mContent = readStream(resolver.openInputStream(Uri.parse(capturedImage.toString())));
		                // 将字节数组转换为ImageView可调用的Bitmap对象
		                bitmap = getPicFromBytes(mContent, null);
		                //把得到的图片绑定在控件上显示
		                ((ImageView)findViewById(R.id.camera_dispaly)).setImageBitmap(bitmap);
		            } catch (FileNotFoundException e) {
		                e.printStackTrace();
		            }
		        } catch (Exception e) {
		        }
	}

3.OK

你可能感兴趣的:(Android)