0

Bitmapに表示されているカメラ プレビューにを描画しようとしていTextureViewます。開発者ガイドは私にこれを教えてくれました:

「1 つのプロデューサーのみが TextureView を使用できることに注意することが重要です。たとえば、TextureView を使用してカメラ プレビューを表示する場合、lockCanvas() を使用して TextureView に同時に描画することはできません。」

そのため、カメラのプレビューと他のビューの両方を FrameLayout に保持したいのですが、写真を撮ろうとすると、TextureView が完全に黒くなります。

ここにいくつかのコードがあります:

View photoFrame = this.findViewById(R.id.fl_photo_frame);
    photoFrame.setDrawingCacheEnabled(true);
    photoFrame.buildDrawingCache();
    Bitmap picture = photoFrame.getDrawingCache();
    photoFrame.destroyDrawingCache();
    try {
        File file = new File(filePath);
        OutputStream outputStream = new FileOutputStream(file);
        picture.compress(Bitmap.CompressFormat.JPEG, 95, outputStream);
        outputStream.flush();
        outputStream.close();
    } catch (FileNotFoundException e) {
        Log.e("Error", "takePhoto: " + e.getMessage());
    } catch (IOException e) {
        Log.e("Error", "takePhoto: " + e.getMessage());
    }

そしてxmlの一部:

<FrameLayout android:id="@+id/fl_photo_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal">

            <TextureView
                android:id="@+id/textureView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal" />

            <FrameLayout android:id="@+id/fl_overlay_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center">

                <ImageView android:src="@drawable/icon"
                    android:layout_width="32dp"
                    android:layout_gravity="center"
                    android:layout_height="32dp"/>
            </FrameLayout>
        </FrameLayout>

後ほどいろいろ追加しますfl_overlay_container

取得した画像は完全に黒く、アイコンが中央にあります

4

0 に答える 0