Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我怎样才能从640*X大屏幕的相机取回照片?_Android_Bitmap_Out Of Memory_Image Scaling - Fatal编程技术网

Android 我怎样才能从640*X大屏幕的相机取回照片?

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

您好,我现在调用camera intent whit参数来放置图像,如下所示:

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(文件路径,选项)两次?为了知道图像的边界,我希望这是一种设置样本大小的方法