In onPictureTaken , I want to do the following:
Bitmap decodedPicture = BitmapFactory.decodeByteArray(data, 0, data.length); Matrix matrix = new Matrix(); matrix.preScale(-1.0f, 1.0f); Bitmap picture = Bitmap.createBitmap(decodedPicture, 0, 0, decodedPicture.getWidth(), decodedPicture.getHeight(), matrix, false); View v1 = mainLayout.getRootView(); v1.setDrawingCacheEnabled(true); Bitmap screenshot = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); Bitmap scaledPicture = Bitmap.createScaledBitmap(picture, screenshot.getWidth(), screenshot.getHeight(), true); Bitmap compos = Bitmap.createBitmap(scaledPicture.getWidth(), scaledPicture.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(compos); canvas.drawBitmap(scaledPicture, new Matrix(), null); canvas.drawBitmap(screenshot, new Matrix(), null); MediaStore.Images.Media.insertImage(getContentResolver(), compos, "name" , "description"); sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
My only requirement is that I would like to keep a high-quality photograph ... It seems I may have to sacrifice this.
On my Nexus 4 and newer devices, this code works just fine and as expected. But on older devices that have less memory, I run out of RAM !: (
How do I do the same image manipulation without encountering memory limitations? I am not trying to display these images on the screen, so the solutions that are related to the thumbnail do not really apply here ...
source share