7

I need to get camera preview data only, but not visible preview. Since I'm doing all this in a service, I had to create a dummy SurfaceView, which works very well.

I've used the code from this answer: https://stackoverflow.com/a/10268650/1395697

However, with TYPE_SYSTEM_OVERLAY it didn't work. It was invisible but no preview data was received (in onPreviewFrame()). When I change this argument to 0, I get preview data, but the SurfaceView is visible.

Do you know any other way to do this?

What I did now is just make a visible SurfaceView with width and height of 1 and then I create an ImageView overlay with a specific color so that you don't see the change of color of the SurfaceView. But this isn't neat at all and I'd really like to do it a bit better.

Community
  • 1
  • 1
DominicM
  • 2,186
  • 5
  • 24
  • 42

2 Answers2

1

i also used the same stackOverflow answer, and get the same problem.so:

i've added this code

this.setZOrderOnTop(true);
SurfaceHolder h = this.getHolder();
h.setFormat(PixelFormat.TRANSPARENT);

to my surfaceChanged method, instead of the activity (or a service at my case), and got it trasparent, but the Log complains on abandoned frames :(

Arkady
  • 624
  • 1
  • 8
  • 17
-1

You don't actually have to place the SurfaceView on your UI at all. We were running into the same issue and made a dummy SurfaceView. Here's our code:

SurfaceView dummy = new SurfaceView(c);
try {
    mCamera.setPreviewDisplay(dummy.getHolder());
} catch (IOException e) {

}
mCamera.setPreviewCallback(this);
mCamera.startPreview();
Zaid Daghestani
  • 8,555
  • 3
  • 34
  • 44
  • 2
    Thats what I thought too. On most devices it even works without a preview display, so your method obviously works too on these devices. However, on some devices like HTC One X or Google Nexus One it doesn't work without a SurfaceView nor with your method – DominicM Jun 09 '12 at 09:40
  • Holy crap. Thank you for solving our problem. We didn't have either to test it on, so we had no idea what was going on. Much appreciated! :D – Zaid Daghestani Jun 09 '12 at 09:41
  • I didn't have one of those to test it either, but I got some bug reports, so I released an update with your method and I asked them whether it worked now and it still didn't. With the new update it finally worked (with the method in my question) but I'd still like to improve it since my method is really horrible I think... – DominicM Jun 09 '12 at 09:49
  • Hmm yeah I've been looking into it, and the only method that seemed to work was ours, but apparently it's only on some devices. I wonder if there is a way to use this method on devices that it works on and the other method on devices that it doesn't. – Zaid Daghestani Jun 09 '12 at 10:23