woshidan's loose leaf

ぼんやり勉強しています

回転が難しいというか、3つくらいこけてるとどこでこけてるかわからんね 2

  • 純正のカメラアプリでもPORTRAITだけ対応だったりするので、回転してすぐカメラのプレビューが取れないとかはまあある話なのでは
    • 単一方向で対応してその先はその後考えようか
  • バッファとかの回転のマトリックスは固定値返したりとかあるみたいですね
  • rotateとかtranslateの中心座標指定めっちゃ便利
  • pauseからの復帰で戻ってくると CameraDevice.StateCallback のonErrorでエラーコード 1 = (ERROR_CAMERA_IN_USE) を受け取る
    • このエラーは優先的にCamera APIを利用してるクライアントがありますよ、と言う意味だが、もちろんいまテスト用に書いてるものしか利用してないので、そのクライアントは自分のこととなる
      • ロック、ロックお前なのか…
    • 明日はあのサンプルの仰々しいロックの導入を試して見るかなー

Matrix 中心座標を入れられるの便利

    private Matrix getDirectionAdjustedMatrix() {
        //  Surface.ROTATION_90 == landscape
        Matrix matrix = new Matrix();
        int viewCenterX = (int) (mTextureView.getX() + mTextureView.getWidth() / 2);
        int viewCenterY = (int) (mTextureView.getY() + mTextureView.getHeight() / 2);

        matrix.postRotate(270 /* sensorOrientation などとの兼ね合いから決まる */, viewCenterX, viewCenterY);
        matrix.postScale((1.0f * IMAGE_WIDTH / IMAGE_HEIGHT) * (mTextureView.getWidth() / mTextureView.getHeight()), (1.0f * IMAGE_HEIGHT / IMAGE_WIDTH) * (mTextureView.getWidth() / mTextureView.getHeight()),
                viewCenterX,  viewCenterY);

        return matrix;
    }

onPause -> onResumeの復帰がうまくいかない

    @Override
    public void onPause() {
        if (mCaptureSession != null) {
            mCaptureSession.close();
            mCaptureSession = null;
        }
        if (mImageReader != null) {
            mImageReader.close();
            mImageReader = null;
        }
        super.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();

        // When the screen is turned off and turned back on, the SurfaceTexture is already
        // available, and "onSurfaceTextureAvailable" will not be called. In that case, we can open
        // a camera and start preview from here (otherwise, we wait until the surface is ready in
        // the SurfaceTextureListener).
        if (mTextureView.isAvailable()) {
            openCamera();
        } else {
            mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
                @Override
                public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
                    // 先ほどのカメラを開く部分をメソッド化した
                    openCamera();
                }

                @Override
                public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {

                }

                @Override
                public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
                    return true;
                }

                @Override
                public void onSurfaceTextureUpdated(SurfaceTexture surface) {

                }

            });
        }
    }
    public static abstract class StateCallback {
       /**
         * An error code that can be reported by {@link #onError}
         * indicating that the camera device is in use already.
         *
         * <p>
         * This error can be produced when opening the camera fails due to the camera
        *  being used by a higher-priority camera API client.
         * </p>
         *
         * @see #onError
         */
        public static final int ERROR_CAMERA_IN_USE = 1;
  • [既存課題]縦向きの場合と横向きの場合でちょうどいいrotationのMatrixを見つける
  • [休止][既存課題]縦向きの場合と横向きの場合でそれぞれちょうどよくCameraのPreviewが表示されるようにする
  • [新しい課題]Pauseからうまく復帰できない