I posted this earlier and it was flagged as a duplicate post. I then clarified my write-up to show that the suggested solution didn't apply to my problem and I was encouraged to resubmit my question. However, the duplicate flag on that post means that I'm being overlooked, so maybe someone will see this instead.
I'm trying to create an app that will take a screenshot of a selected area. Its a FrameLayout containing a cameraView. I am placing extra views on this layout - the best example I can give is like a pilot seeing an indtrument readout superimposed on top of his "normal" vision. I'm trying to take a screenshot of the cameraview, with the extra material superimposed on top.
I am "using" the cameraview as a textureview, not surface view (the suggested solution on the other post was for surfaceview)
However, when I do it, the "extra" views that had been placed on the camera view show up on the resultant saved image but the cameraview "background" itself is black even though I can see the camera's output on my app when I save the image. In other words, other than the background from the camera with foreground material, there is only the foreground material and a black background
Can anyone help?
My layout xml for this part of the code is:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frlayout"
android:layout_weight="0.82"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextureView
android:id="@+id/cameraView"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
And the code that saves the image is:
Bitmap bitmap;
ViewGroup v1 = findViewById(R.id.frlayout);
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = Environment.getExternalStorageDirectory()+ "/" + timeStamp + ".jpg";
OutputStream fout = null;
File imageFile = new File(imageFileName);
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 95, fout);
fout.flush();
fout.close();
} catch (Exception e) {
}