Friday, September 10, 2010

[android-developers] camera preview + takePicture + added graphics- help!

I am making an Android application that uses the camera- and also
draws on the screen.
Basically, I want to start out with the camera preview mode- and then
when i double tap, take a photo. After the photo is taken, i want the
screen to show a bitmap that i created from the photo. (i can
successfully create this bitmap and save it to SD card). After another
double tap, i want to go back to camera preview mode.

I get the basics- ie, gestures, how to use a camera, how to draw,
separately- but together, the camera and graphics are really confusing
me. Any tips on how I should structure the code?

Right now I have 2 main classes:
1) public class FrameFaces extends Activity implements
OnGestureListener, OnDoubleTapListener
[has onCreate, onDestroy, etc, and gesture stuff.. in here I
create a GraphicsView view-

view = new GraphicsView(this);
setContentView(view);
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();

i then call view.draw() and then view.invalidate()
]
and

2) public class GraphicsView extends SurfaceView implements
SurfaceHolder.Callback
[has Camera, SurfaceHolder, surfaceCreated/destroyed/etc- one of
my constructors looks like this:

public GraphicsView(Context context)
{
super(context);
this.setFocusable(true);
this.setFocusableInTouchMode(true);
holder = this.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

}

my main method in here is onDraw- which i know works in terms of
painting the canvas and bitmap the way i want.

I also have static variables that I'm sharing between the 2 classes
because I think I need access to the camera and canvas in both- I'm
not sure if this is a bad idea, and if i'm totally confused about how
surface holders work in this context.
------------

Right now: this is what's happening.
It starts, and the activity responds to gestures, but the screen is
blank. So Im figuring I am in trouble with the camera- failing to
connect to camera service. Ive tried all sort of camera open, close,
startPreview, stopPreview, release, -- like I said, i can do this when
Im just working on a simple camera application.

OK. This is a lot. But if anyone has advice on how to structure this
better, please let me know- I can also send my code if needed. Sorry
if this is confusing, I can clarify. I'm just freaking out because I
have to run studies next week and this is driving me insane.

Thanks thanks thanks.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment