Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6350831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:53:11+00:00 2026-05-24T21:53:11+00:00

I am trying to display the camera preview with an image overlay and have

  • 0

I am trying to display the camera preview with an image overlay and have a button at the bottom to take the picture. I pretty much copied the API from CameraPreview and added an addcontentview which seems to work pretty well for adding an xml file which acts as my overlay. (Except that it has to be in landscape mode so I need to figure out how to either rotate all my stuff through code or, easier for me, just make sideways images :-P)

My problem is that I just can’t figure out how to get my button to work correctly.

All I want to do is use the image as the background for my next activity. Anyway, this is what I’ve got.

public class CameraPreview extends Activity {    
    private Preview mPreview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        mPreview = new Preview(this);
        setContentView(mPreview);
        LayoutInflater inflater = getLayoutInflater();
        getWindow().addContentView(inflater.inflate(R.layout.overlay, null), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
        ViewGroup.LayoutParams.FILL_PARENT));           
    }
}


// ----------------------------------------------------------------------

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

    Preview(Context context) {
        super(context);

        mHolder = getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);                               
    }

    public void surfaceCreated(SurfaceHolder holder) {
        mCamera = Camera.open();
        try {
           mCamera.setPreviewDisplay(holder);
        } catch (IOException exception) {
            mCamera.release();
            mCamera = null;
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        mCamera.stopPreview();
        mCamera.release();
        mCamera = null;
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPreviewSize(w, h);
        mCamera.setParameters(parameters);
        mCamera.startPreview();
    }
}

I just can’t figure out where to put in my button, what to type or anything. I’m assuming its something like camera.takepicture but I can’t get it to work.

Oh yea, I’ve spent about half the day on this one area so if you could super simplify it for me, my fried mind would appreciate it. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:53:12+00:00Added an answer on May 24, 2026 at 9:53 pm

    Alright, I poked around a little today with a fresh mind and decided it would be much easier to just have the user use their camera app. So I did that with a startActivityForResult and from there it was a cinch to modify my imageview with the data and I just am going to put my overlay onto the returned preview using RelativeLayout.

    Thanks if you were working on this. I pulled from the question below to make mine.

    How do I save data from Camera to disk using MediaStore on Android?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to display image when left mouse button is down. i can display
I'm trying to display an image on top of a surface where a camera
I am trying to display a .md2 model over top of the camera preview
I am trying to display a filtered camera preview, using onPreviewFrame() callback. The problem
I'm trying to display a picture in an openGL environment. The picture's origninal dimensions
I'm trying to modify the SurfaceView I use for doing a camera preview in
I'm trying to display a UIImage in real-time coming from the camera, and it
This is a very beginner problem. I'm trying to display an image taken with
I am trying to capture video from a camera. i have gotten the captureOutput:didOutputSampleBuffer:
I'm trying to make a basic application that displays an image from the camera,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.