开发者

Change Camera settings from another App's Activity

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.

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(),
            "fna开发者_StackOverflow中文版me_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);

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.

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)

  • Downsampling. Sample size should be greater than 1. Try 2 and 4.

    BitmapFactoryOptions.inSampleSize = sampleSize;

  • 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();
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜