从另一个应用程序的活动更改相机设置 [英] Change Camera settings from another App's Activity
问题描述
我有一个Android应用程序调用本机相机应用拍照并返回进一步处理图像。我的问题是,我遇到了内存泄漏如果相机设置为2(+)百万像素。理想情况下,我想将它设置为最低(VGA),因为图像质量不符合这个应用程序关心的问题。
I have an Android app that calls the native camera app to take a picture and returns the image for further manipulation. My problem, is that I run into memory leaks if the camera is set to 2(+) megapixels. Ideally, I want it set to the lowest (VGA) since image quality is not a concern with this app.
有没有从我的应用程序的方式来改变本地设备的相机应用的设置?这里是code我使用的:
Is there a way from my app to change the settings of the native device's camera app? Here is the code I am using:
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);
任何帮助将是AP preciated。
Any help would be appreciated.
推荐答案
不幸的是没有告诉你要采取的照片是什么照片分辨率相机应用程序的方式。
Unfortunately there is no way of telling the camera application what picture resolution you want to take the picture at.
但你但是,可以通过一些acesssing功能位像(第二个选项会更适合你的需求)做点什么自己在你的应用程序
But you can however do something about it yourself in your app by acesssing some bitmap functionalities like (2nd option would be more suited for your needs)
-
下采样。样本量应大于1.尝试2和4。
Downsampling. Sample size should be greater than 1. Try 2 and 4.
BitmapFactoryOptions.inSampleSize =采样大小;
创建与您从原来的位图要求大小的新位图..
Creating a new bitmap with the size that you require from the original bitmap..
// 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();
这篇关于从另一个应用程序的活动更改相机设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!