0

I'm working on a project that I need to save the camera picture based on a face detection. the part of face detection is done based on google examples but the problem is in saving the CameraSourcePreview into a jpg file. I am only able to save overlay of camera feed with a black background!

my mainActivity.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLayout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">

  <com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview
      android:id="@+id/preview"
      android:drawingCacheQuality="auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

    <com.google.android.gms.samples.vision.face.facetracker.ui.camera.GraphicOverlay
        android:id="@+id/faceOverlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

  </com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview>

</LinearLayout>

my code for saving:

CameraSourcePreview csp    
csp.setDrawingCacheEnabled(true);
                    File f = new File(Environment.getExternalStorageDirectory().getPath()+"/" + currentTime.toString() + ".jpg");
                    Bitmap bmp = Bitmap.createBitmap(csp.getDrawingCache());
                    csp.setDrawingCacheEnabled(false);
                    bmp.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(f));
                    lastPic = currentTime.getTime();

where is the problem? is it because the overlay is infront of the camera feed? how can i make black pixels transparetn?

edit:

the differnce between my case and other questions is that i want to save the real time pic not the taken image. this question is not repeated. my clear question is where is camera picture that i can see in the screen? why it did not save in jpg file?

mohamad ali gharat
  • 501
  • 1
  • 5
  • 10
  • Step-by-step instructions can be found in this answer: https://stackoverflow.com/a/18299259/192373 – Alex Cohn Feb 02 '18 at 19:50
  • Actually, I know how to save it. my question is why it has the black background and where is the camera picture? – mohamad ali gharat Feb 02 '18 at 19:54
  • The answer above gives the explanation, but I don't mind to repeat it here. Camera preview goes to SurfaceView directly, and is not registered for View DrawingCache. Same is true for GLSurfaceView. That's why your bitmap has black pixels. – Alex Cohn Feb 02 '18 at 21:31

0 Answers0