0

I'm trying to draw a Bitmap onto a camera preview that is displayed in a TextureView. The developers guide told me this:

"It is important to note that only one producer can use the TextureView. For instance, if you use a TextureView to display the camera preview, you cannot use lockCanvas() to draw onto the TextureView at the same time."

So now I want to keep both the camera preview and the other view in a FrameLayout but when I try to take a picture, the TextureView is completely black.

Here's some code:

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

And a part of the 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>

I will add more stuff to fl_overlay_container later.

The images I get are completely black, with the icon in the center

4

0 回答 0