Android大图像旋转
我试图在500万像素左右旋转使用Android设备的相机拍摄的图像。不幸的是它只能使用一次。之后,我得到了“内存不足”的例外。即使我释放以前使用过的图像,它看起来像它的数据仍然占用内部图像堆/存储,并以某种方式阻止了进一步的旋转操作。有没有什么好的方法可以解决这个问题(例如,免费的图像存储器,旋转图像而不需要两倍的内存大小)?Android大图像旋转
你是如何动画的? 确保您使用的是位图回收。 看看这篇文章,应该是有帮助的:
http://mobi-solutions.blogspot.com/2010/08/how-to-if-you-want-to-create-and.html
在相机给你一个已旋转图像:
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);
}
我在哪里可以得到cameraId的值? – dannyroa 2013-04-30 20:32:05
_cameraId_是从0到_getNumberOfCameras()_的值,请参阅http://developer.android.com/reference/android/hardware/Camera.html#getNumberOfCameras()和_Camera.open()_函数。 – 18446744073709551615 2013-05-06 07:24:25
谢谢你的文章。我已经熟悉回收和gc了,它在这里不起作用。我现在隔离了这个问题,看起来好像发生在相机预览使用后。 – georgij 2011-03-22 21:47:09