Take a Picture without a GUI

All your problems with Audio, Video and Images.

Take a Picture without a GUI

Postby canadiancow » Tue Sep 01, 2009 9:04 pm

All the code I've seen for taking pictures seem to involve a class that extends Activity, and often implements SurfaceHolder.Callback.

I'm trying to write a service that will periodically take a picture, and as such, I don't want a GUI.

Can anyone provide an example of how to achieve this?

Thanks
canadiancow
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Aug 31, 2009 2:36 pm

Top

Postby canadiancow » Tue May 11, 2010 3:57 am

Well it's been 8 months, and I still don't have an answer on this.

Any help would be greatly appreciated.
canadiancow
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Aug 31, 2009 2:36 pm

Postby pskink » Tue May 11, 2010 7:13 am

canadiancow wrote:Well it's been 8 months, and I still don't have an answer on this.

Any help would be greatly appreciated.


did you try Camera without attaching to SurfaceView?
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby nicholas.hauschild » Tue May 11, 2010 1:23 pm

There is no requirement to implement the SurfaceHolder.Callback interface when making a Camera application. That would be used to give a 'live' feed of what the camera is currently seeing.

You should be able to use the camera mechanism to take pictures periodically in a background service, and save those pictures into the MediaStore on the device.

Good Luck!
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Postby canadiancow » Tue May 11, 2010 2:19 pm

nicholas.hauschild wrote:There is no requirement to implement the SurfaceHolder.Callback interface when making a Camera application. That would be used to give a 'live' feed of what the camera is currently seeing.

You should be able to use the camera mechanism to take pictures periodically in a background service, and save those pictures into the MediaStore on the device.

Good Luck!
-Nick


No. Unless I am missing something obvious:

Camera.setPreviewDisplay(SurfaceHolder holder) must be called with a valid surface to take pictures, or it will fail.
MediaRecorder.setPreviewDisplay(Surface sv) must be called with a valid surface to record video, or it will fail.
canadiancow
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Aug 31, 2009 2:36 pm

Postby pskink » Tue May 11, 2010 2:34 pm

canadiancow wrote:No. Unless I am missing something obvious:

Camera.setPreviewDisplay(SurfaceHolder holder) must be called with a valid surface to take pictures, or it will fail.
MediaRecorder.setPreviewDisplay(Surface sv) must be called with a valid surface to record video, or it will fail.


did you try:

Camera.setPreviewDisplay(null) ?
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Postby canadiancow » Tue May 11, 2010 2:58 pm

pskink wrote:
canadiancow wrote:No. Unless I am missing something obvious:

Camera.setPreviewDisplay(SurfaceHolder holder) must be called with a valid surface to take pictures, or it will fail.
MediaRecorder.setPreviewDisplay(Surface sv) must be called with a valid surface to record video, or it will fail.


did you try:

Camera.setPreviewDisplay(null) ?


Yes. It failed with a message along the lines of "a preview display must be set". At this point, I'm looking for a hack to let me do it.
canadiancow
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Aug 31, 2009 2:36 pm

Postby pskink » Tue May 11, 2010 3:13 pm

canadiancow wrote:Yes. It failed with a message along the lines of "a preview display must be set". At this point, I'm looking for a hack to let me do it.


just tried:

Camera.open().takePicture(null, null, this)

and it worked...

in jpeg callback i got valid data and release()ed the Camera
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby canadiancow » Tue May 11, 2010 3:27 pm

pskink wrote:
canadiancow wrote:Yes. It failed with a message along the lines of "a preview display must be set". At this point, I'm looking for a hack to let me do it.


just tried:

Camera.open().takePicture(null, null, this)

and it worked...

in jpeg callback i got valid data and release()ed the Camera


Interesting. I'll try it again when I get home.

Any ideas for MediaRecorder and video?
canadiancow
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Aug 31, 2009 2:36 pm

Postby pskink » Tue May 11, 2010 3:39 pm

canadiancow wrote:
Any ideas for MediaRecorder and video?


no :-(
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby canadiancow » Tue May 11, 2010 4:07 pm

pskink wrote:
canadiancow wrote:
Any ideas for MediaRecorder and video?


no :-(


Actually, can you clarify how you tested the camera?

From what I recall (and I'll admit, I haven't tried to do this in months, as I"m working with video now), the emulator will spit out its standard image regardless of whether you have a preview surface. The actual device will just give you a black rectangle.
canadiancow
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Aug 31, 2009 2:36 pm

Postby pskink » Tue May 11, 2010 4:17 pm

canadiancow wrote:From what I recall (and I'll admit, I haven't tried to do this in months, as I"m working with video now), the emulator will spit out its standard image regardless of whether you have a preview surface. The actual device will just give you a black rectangle.


oh, my bad, didn't know that Camera emulation is so poor...

but if you really need SurfaceHolder can't you create a SurfaceView without attaching it to anything but Camera?
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby canadiancow » Tue May 11, 2010 4:38 pm

pskink wrote:
canadiancow wrote:From what I recall (and I'll admit, I haven't tried to do this in months, as I"m working with video now), the emulator will spit out its standard image regardless of whether you have a preview surface. The actual device will just give you a black rectangle.


oh, my bad, didn't know that Camera emulation is so poor...

but if you really need SurfaceHolder can't you create a SurfaceView without attaching it to anything but Camera?


It doesn't work.
canadiancow
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Aug 31, 2009 2:36 pm

Re: Take a Picture without a GUI

Postby SirBastian » Sat Jul 31, 2010 7:26 am

canadiancow wrote:All the code I've seen for taking pictures seem to involve a class that extends Activity, and often implements SurfaceHolder.Callback.

I'm trying to write a service that will periodically take a picture, and as such, I don't want a GUI.

Can anyone provide an example of how to achieve this?

Thanks


Hi there,

I'm working on an android application with literally the exact same requirement - periodic picture taking in the background, with no preview frames displayed.

I struggled like you with trying to do it without anything set as a display surface for 2 months before I realized that it needs to have something passed.

I tried taking my preview class (which extends SurfaceView and implements SurfaceHolder.Callback) and using setVisibility(View.GONE). For some reason, passing this anything besides View.VISIBLE makes it crash when you takePicture. I'm something of a novice, but this seems like particularly strange behavior - I find it hard to believe that the visibility of a view actually changes its width and height such that takePicture would trip.


Anyway, I'd really love to get an answer to this issue as well. Let's get to the bottom of it!
SirBastian
Freshman
Freshman
 
Posts: 4
Joined: Sat Jul 31, 2010 7:18 am

Re: Take a Picture without a GUI

Postby blundell » Wed Aug 04, 2010 9:09 am

Hey, I haven't got the answer atm but I'll just tease you a little and say it can be done :-) if you check out some of the current apps on the market. Maybe email the dev's they may be kind enough to share the code snippet, an if so share with us ;-)
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top
Next

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 24 guests