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 build a 2d GUI to an OpenGL ES app?

I want to make an OpenGL ES version of my M3G app "Astral 3d worlds".
The app has a 2d GUI, from which you can start 10 visual effects.

I can port the  visual effects to OpenGL ES, but how can I build the
2d GUI? Should I really use OpenGL ES for that?


2. Android Implementation of Multitouch


I have a question; why doesn't the android browser pinch zoom multi
touch feel quite right?

Answer? Because it's weird!

Here's the thing: pinch zoom is not a gesture, it's an interaction
with the page. So, what it shouldn't be is measuring the change in
distance between your fingers and then scaling what your're viewing by
a certain amount. What it should be is pinning your fingers to places
on the page, and as they move scaling *and moving* the page in order
to keep your fingers on the same places on the page. This is what
happens (give or take) on the gallery - so why not on the browser.

This is particularly useful when you want to zoom in on something in
one corner of the page - you stick your fingers on the corners of it,
and then move them to the far sides of the screen. Unfortunately, with
the current implementation, it zooms in on the centre of the page
(actually, somewhere in the direction of where your fingers are, but
not quite there!), and you're left having to then scroll after
zooming. Unnecessary.

I hope that makes sense to someone who thinks it'd be worth
implementing... I certainly think so!




3. select (mac) query problem.

4. Alsa + audioflinger latency for audio when playing over AudioTrack + MODE_STREAM

5. How is CallLog updated when Contact information changed?

6. Theter d cyanogen mod...

7. Camera 360's Ghost templates [was: Aplikasi ghost radar]