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 6195953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:33:35+00:00 2026-05-24T03:33:35+00:00

I have a SurfaceView that is being used to draw images, and I would

  • 0

I have a SurfaceView that is being used to draw images, and I would like to overlay them onto a live-feed from the phone’s camera. I have read Overlay images onto camera preview surfaceview
and how to draw an overlay on a surfaceview used by camera on android

    public class TestCameraOverlayActivity extends Activity { 
         Bitmap bitmap;

         /** Called when the activity is first created. */ 
         @Override 
         public void onCreate(Bundle savedInstanceState) { 
               super.onCreate(savedInstanceState); 
               requestWindowFeature(Window.FEATURE_NO_TITLE); 
               Preview mPreview = new Preview(this); 
               DrawOnTop mDraw = new DrawOnTop(this); 
               bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
               setContentView(mPreview); 
               addContentView(mDraw, new LayoutParams (LayoutParams.WRAP_CONTENT,
               LayoutParams.WRAP_CONTENT)); 
        } 

        class DrawOnTop extends View { 
            public DrawOnTop(Context context) { 
                super(context); 

        } 

        @Override 
        protected void onDraw(Canvas canvas) { 
            Paint paint = new Paint(); 
            paint.setStyle(Paint.Style.STROKE); 
            paint.setColor(Color.BLACK); 
            canvas.drawText("Test Text", 10, 10, paint); 
            canvas.drawBitmap(bitmap, 0, 0, null);
            super.onDraw(canvas); 
        } 
    } 

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

        Preview(Context context) { 
            super(context); 
            // Install a SurfaceHolder.Callback so we get notified when the 
            // underlying surface is created and destroyed. 
            mHolder = getHolder(); 
            mHolder.addCallback(this); 
            mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
        } 

        public void surfaceCreated(SurfaceHolder holder) { 
            // The Surface has been created, acquire the camera and tell it where 
            // to draw. 
            mCamera = Camera.open(); 
             try {
        mCamera.setPreviewDisplay(holder);
        } catch (IOException e) {

            e.printStackTrace();
        } 
        } 

        public void surfaceDestroyed(SurfaceHolder holder) { 
           // Surface will be destroyed when we return, so stop the preview. 
           // Because the CameraDevice object is not a shared resource, it's very 
           // important to release it when the activity is paused. 
           mCamera.stopPreview(); 
           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); 
            mCamera.setParameters(parameters); 
            mCamera.startPreview(); 
       } 
    } 
 }

if you run it you can one see image on the preview SurfaceView, but my question is how to save them together as jpeg on the sdcard. Can you give some advice, if i need Format conversion so that i can save them at the same time. My partial solution to save the image only

/** Handles data for jpeg picture */
PictureCallback jpegCallback = new PictureCallback() {

public void onPictureTaken(byte[] data, Camera camera) {
    FileOutputStream outStream = null;
try {
    // write to local sandbox file system
        // outStream = CameraDemo.this.openFileOutput(String.format("%d.jpg", 
           System.currentTimeMillis()), 0); 

        // Or write to sdcard
    outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", 
        System.currentTimeMillis()));   
    outStream.write(data);
    outStream.close();
    Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
} finally {
}
Log.d(TAG, "onPictureTaken - jpeg");
}
};
  • 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-24T03:33:35+00:00Added an answer on May 24, 2026 at 3:33 am

    I think you are asking how to merge the two images into one.

    The first thing you should do is use an AsynchHandler to save your image so you don’t lock up the UI, that’s not part of your issue but it will be.

    As to your general question it was asked and answered here in general you will need to merge the two image parts together and handle scaling of your overlay as a whole, or the component image parts.

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

Sidebar

Related Questions

I have a SurfaceView that I draw onto, there are no controls, text boxes
I currently have a SurfaceView (named BoardView) that is being stored in a FrameLayout.
I have an app that uses a Class with an extension SurfaceView to draw
I have a custom SurfaceView that looks like this: public class GFXSurface extends Activity
HI! I have a surfaceView inside a horizontal scrollview that I want to fill
I'm using SurfaceView to draw some stuff using canvas. The problem is that I
In a SurfaceView, I'm dispatching new thread that draws on canvas within standard LockCanvas-Draw-unlockCanvasAndPost
I have three views in my app and I would like to be able
When you have a surfaceView class, used for animation/game/... you have the onTouchEvent() method
I have a third party framework that shows video on a SurfaceView . I

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.