【问题标题】:Change Camera settings from another App's Activity从另一个应用的 Activity 更改相机设置
【发布时间】:2011-09-07 03:58:17
【问题描述】:

我有一个 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);

任何帮助将不胜感激。

【问题讨论】:

    标签: android camera android-intent mediastore android-camera-intent


    【解决方案1】:

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

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

    • 下采样。样本量应大于 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();
      

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 2016-05-26
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      相关资源
      最近更新 更多