0

我有一个 Android 应用程序,它调用本机相机应用程序来拍照并返回图像以供进一步操作。我的问题是,如果相机设置为 2(+) 百万像素,我会遇到内存泄漏。理想情况下,我希望将其设置为最低 (VGA),因为此应用程序不关心图像质量。

我的应用程序有没有办法更改本机设备的相机应用程序的设置?这是我正在使用的代码:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            mImageCaptureUri = 
            Uri.fromFile(new file(Environment.getExternalStorageDirectory(),
            "fname_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);

任何帮助,将不胜感激。

4

1 回答 1

0

不幸的是,没有办法告诉相机应用程序你想用什么分辨率拍照。

但是您可以通过访问一些位图功能(例如,第二个选项更适合您的需求)在您的应用程序中自己做一些事情

  • 下采样。样本量应大于 1。尝试 2 和 4。

    BitmapFactoryOptions.inSampleSize = sampleSize;

  • 从原始位图中创建具有所需大小的新位图..

    // calculate the change in scale 
    float scaleX = ((float) newWidth_that_you_want) / originalBitmap.width();
    float scaleY = ((float) newHeight_that_you_want) / originalBitmap.height();
    
    // createa matrix for the manipulation
    Matrix matrix = new Matrix();
    matrix.postScale(scaleX , scaleY );
    
    Bitmap newBitmap = Bitmap.createBitmap(originalBitmap, 0, 0, width, height, matrix, true);
    //since you don't need this bitmap anymore, mark it so that GC can reclaim it.
    //note: after recycle you should not use the originalBitmap object anymore.
    //if you do then it will result in an exception.
    originalBitmap.recycle();
    
于 2011-09-08T13:52:52.983 回答