开发者

Android Large Image Rotation

I'm trying to rotate images taken with the camera of an Android device at around 5MP. Unfortunately it works only once. After that I get a "not enough memory" exception. Even though I rele开发者_高级运维ase the former used image it looks like its data still occupy the internal image heap/storage and somehow prevent further rotation operations. Are any good ways known for how to handle this problem (e.g. free image memory, rotate images without needing twice the size in memory)?


Making the camera give 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);
    }


How are you animating it? Make sure you are using bitmap recycle. Take a look at this article, it should be helpful:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜