gpt4 book ai didi

安卓大图旋转

转载 作者:行者123 更新时间:2023-11-29 02:14:14 24 4
gpt4 key购买 nike

我正在尝试以大约 5MP 的速度旋转使用 Android 设备的相机拍摄的图像。不幸的是它只工作一次。之后我得到一个“内存不足”的异常。即使我释放了以前使用过的图像,它看起来它的数据仍然占用内部图像堆/存储并以某种方式阻止进一步的旋转操作。是否有任何已知的解决此问题的好方法(例如,释放图像内存,旋转图像而不需要两倍的内存大小)?

最佳答案

让相机给你一个已经旋转的图像:

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

关于安卓大图旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5372620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com