how to overlay an image over the camera preview?

by srajpal » Sat, 31 Jan 2009 07:48:57 GMT

Sponsored Links
 Does someone know how I can overlay an image over the camera preview?

how to overlay an image over the camera preview?

by srajpal » Sat, 31 Jan 2009 09:31:49 GMT

 I checked out the api demo, it helps to place the camera preview on
top of the surface view, but the buffers are handid over to the camera
so anything drawn on the canvas, which is received from the handler,
is ignored.

There must be some way.  I just don't know it yet.


Sponsored Links

how to overlay an image over the camera preview?

by Dave Sparks » Sat, 31 Jan 2009 09:44:50 GMT

 No, you don't draw on the camera preview surface. You create a
transparent surface above it in the Z stack and draw on that.


how to overlay an image over the camera preview?

by srajpal » Sun, 01 Feb 2009 10:56:47 GMT

 sounds good, do you have an example piece of code or can you please
point me to something.


how to overlay an image over the camera preview?

by srajpal » Sun, 01 Feb 2009 12:01:17 GMT

 layed around with this a little and solved it just like Dave Sparks
Thank you Dave
here is the code

import android.content.Context;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.ViewGroup.LayoutParams;

public class TestCameraOverlay extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {


Preview mPreview = new Preview(this);
DrawOnTop mDraw = new DrawOnTop(this);

addContentView(mDraw, new LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));


class DrawOnTop extends View {

public DrawOnTop(Context context) {
// TODO Auto-generated constructor stub

protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub

Paint paint = new Paint();
canvas.drawText("Test Text", 10, 10, paint);




class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;

Preview(Context context) {

// Install a SurfaceHolder.Callback so we get notified when
// underlying surface is created and destroyed.
mHolder = getHolder();

public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell
it where
// to draw.
mCamera =;

public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the
// Because the CameraDevice object is not a shared resource,
it's very
// important to release it when the activity is paused.
mCamera = null;

public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h) {
// Now that the size is known, set up the camera parameters
and begin
// the preview.
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);


On Jan 31, 9:56pm, srajpal <> wrote:

Other Threads

1. How to add Diff Views in Expandable List?

I need to add a table layout with an expandable list as a child in one of
the children of an expandable list.That is in the apis already provided we
have a single level expandable list.I want to add table as the child.And in
turn in the table i have an expandable list.How do i acheive this?

I tried the code below:

    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {

        if (groupPosition == 1 && childPosition == 0) {
                TableLayout tableLayout = new TableLayout(context);
                TableLayout.LayoutParams lp = new TableLayout.LayoutParams(
                        ViewGroup.LayoutParams.FILL_PARENT, 500);
                lp.setMargins(40, 0, 0, 0);
                TableRow tableRow = new TableRow(context);
                ExpandableListView expandableListView = new
                ExpandableListAdapter mySubListAdapter = new

                expandableListView.setAdapter(mySubListAdapter );
                return tableLayout;
         }else {
            Log.i(getClass().getName(), "In getChildView ");
            TextView textView = getGenericView();
            return textView;

Also how do I enable logging in these Overriden methods.I dont see the
logs.I able to see the logs in the other methods.

Thanks for your time.


2. Clockwise or Counter-clockwise fling

would anyone have any tip on how I could distinguish between a
clockwise and a counter clockwise fling event?
So far I've been using just velocityX and velocityY which just gives
me the idea of the direction.

I think I could retrieve the absolute position of the ACTION_DOWN
event and likewise the absolute position of the ACTION_UP event. In
this way I would be able to define the equation of the line passing
through these two points. Therefore if I also had a set of points
belonging to the fling movement trajectory I would be able to tell if
those points stay over or underneath that line.
Knowing also if the x and y coordinates are incrementing or
decrementing (velocityX and velocityY) during the flig movement I
would be able to tell if the movement was clockwise or counter-

I am new to android, so I don't know which are the capabilities that
all the different structures offer.

Could anyone tell me his/her idea on what I just tried to expose?



3. source code file

4. How to package application for upload to websites from Eclipse IDE?

5. Where are all the apps

6. Motorola Q skin now available for Android Emulator!

7. Apps for Democracy Contest $20,000 in Prizes