Android 我怎样才能从640*X大屏幕的相机取回照片?
您好,我现在调用camera intent whit参数来放置图像,如下所示:Android 我怎样才能从640*X大屏幕的相机取回照片?,android,bitmap,out-of-memory,image-scaling,Android,Bitmap,Out Of Memory,Image Scaling,您好,我现在调用camera intent whit参数来放置图像,如下所示: imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "tmpPic.jpg")); Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); ca
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "tmpPic.jpg"));
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, 1);
String filePath = Environment.getExternalStorageDirectory() + "/tmpPic.jpg";
if (yourSelectedImage != null)
yourSelectedImage.recycle();
yourSelectedImage = null;
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
options.inSampleSize = 1;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
yourSelectedImage = BitmapFactory.decodeFile(filePath, options);
break;
我在活动结果中检索图像,如下所示:
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "tmpPic.jpg"));
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, 1);
String filePath = Environment.getExternalStorageDirectory() + "/tmpPic.jpg";
if (yourSelectedImage != null)
yourSelectedImage.recycle();
yourSelectedImage = null;
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
options.inSampleSize = 1;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
yourSelectedImage = BitmapFactory.decodeFile(filePath, options);
break;
但在第
行中断之前,您选择了edimage=BitmapFactory.decodeFile(文件路径,选项)代码>它属于内存不足异常。我知道样本大小是获得较小图像的方式,但这是我可以指定在和处使用640*X大位图的方式吗?或者我如何至少跟踪传入的图像太大,我应该使用样本大小?奇怪的是,你得到了OOM,我使用了基本相同的代码,没有任何问题。为什么要调用BitmapFactory.decodeFile(文件路径,选项)代码>两次?为了知道图像的边界,我希望这是一种设置样本大小的方法