Frage

Ich habe eine Android -App, die die native Kamera -App aufruft, um ein Bild aufzunehmen und das Bild zur weiteren Manipulation zurückzugeben. Mein Problem ist, dass ich auf Speicherlecks stoße, wenn die Kamera auf 2 (+) Megapixel eingestellt ist. Im Idealfall möchte ich, dass es auf die niedrigste (VGA) eingestellt ist, da die Bildqualität bei dieser App kein Problem darstellt.

Gibt es einen Weg von meiner App, die Einstellungen der Kamera -App des nativen Geräts zu ändern? Hier ist der Code, den ich verwende:

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);

Jede Hilfe wäre geschätzt.

War es hilfreich?

Lösung

Leider gibt es keine Möglichkeit, der Kameraanwendung zu sagen, in welcher Bildauflösung Sie das Bild machen möchten.

Sie können jedoch in Ihrer App jedoch etwas dagegen tun, indem Sie einige Bitmap -Funktionen wie (2. Option wäre besser für Ihre Anforderungen geeignet)

  • Downsampling. Die Probengröße sollte größer als 1. Versuchen Sie 2 und 4.

    BitmapFactoryOptions.inSampleSize = sampleSize;

  • Erstellen einer neuen Bitmap mit der Größe, die Sie von der ursprünglichen Bitmap benötigen.

    // 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();
    
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top