Android Large Image Rotation

I'm trying to rotate images taken with the camera of an Android device about 5 megapixels in size. Unfortunately, it only works once. After that, I get an "out of memory" exception. Despite the fact that I am releasing the previously used image, it seems that its data still occupies the internal heap of images / storage and somehow prevent further rotation operations. Are there any good ways to solve this problem (for example, free image memory, rotation of images without the need for twice as much memory)?

+2
source share
2 answers

Creating a camera gives you an already rotated image:

public void setCameraDisplayOrientation(int cameraId, android.hardware.Camera camera) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } // set the right preview orientation camera.setDisplayOrientation(result); // make the camera output a rotated image Camera.Parameters cameraParameters = camera.getParameters(); cameraParameters.setRotation(result); camera.setParameters(cameraParameters); } 
+1
source

How do you revive it? Make sure you are using the bitmap utility. Take a look at this article, this should be useful:

http://mobi-solutions.blogspot.com/2010/08/how-to-if-you-want-to-create-and.html

0
source

Source: https://habr.com/ru/post/1382272/


All Articles