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

  • Home
  • SEARCH
  • 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 8186771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:20:16+00:00 2026-06-07T02:20:16+00:00

i have a surface view and i wish draw the content of a linear

  • 0

i have a surface view and i wish “draw” the content of a linear layout on my surface view.

My surface view is the preview of the camera, i wish when i take the picture the content of my layout is drawn on the picture.

How do this?

Thx.

  • 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-06-07T02:20:17+00:00Added an answer on June 7, 2026 at 2:20 am

    Surface layout:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:gravity="bottom"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    
    <ImageView
            android:id="@+id/takepicture"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/trans_tshirt"
            android:contentDescription="tshirt" />
    

    main.xml

    <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
            <SurfaceView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/camerapreview"/>
    </LinearLayout>
    
    
    java code:
    
    package com.views;
    
    import android.app.Activity;
    import android.content.ContentValues;
    import android.content.pm.ActivityInfo;
    import android.graphics.PixelFormat;
    import android.hardware.Camera;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.MediaStore;
    import android.view.LayoutInflater;
    import android.view.SurfaceHolder;
    import android.view.SurfaceView;
    import android.view.View;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.ImageView;
    import android.widget.Toast;
    import com.fashion.alex.R;
    
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.OutputStream;
    
    public class HomeActivity extends Activity implements SurfaceHolder.Callback
    {
    
        private Camera camera;
        private SurfaceView surfaceView;
        private SurfaceHolder surfaceHolder;
        private boolean previewing = false;
        private LayoutInflater controlInflater = null;
    
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    
            getWindow().setFormat(PixelFormat.UNKNOWN);
            surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
            surfaceHolder = surfaceView.getHolder();
            surfaceHolder.addCallback(this);
            surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    
            controlInflater = LayoutInflater.from(getBaseContext());
            View viewControl = controlInflater.inflate(R.layout.tshirt_layout, null);
            LayoutParams layoutParamsControl = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            this.addContentView(viewControl, layoutParamsControl);
            final ImageView ivButton = (ImageView)findViewById(R.id.takepicture);
            ivButton.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    camera.takePicture(myShutterCallback,
                            myPictureCallback_RAW, myPictureCallback_JPG);
                }}
            );
        }
    
        Camera.ShutterCallback myShutterCallback = new Camera.ShutterCallback(){
            @Override
            public void onShutter() {
    
            }
        };
    
        Camera.PictureCallback myPictureCallback_RAW = new Camera.PictureCallback(){
            @Override
            public void onPictureTaken(byte[] arg0, Camera arg1) {
            }
        };
        Camera.PictureCallback myPictureCallback_JPG = new Camera.PictureCallback(){
            @Override
            public void onPictureTaken(byte[] arg0, Camera arg1) {
                Uri uriTarget = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
                OutputStream imageFileOS;
                try {
                    imageFileOS = getContentResolver().openOutputStream(uriTarget);
                    imageFileOS.write(arg0);
                    imageFileOS.flush();
                    imageFileOS.close();
                    Toast.makeText(HomeActivity.this,
                            "Image saved: " + uriTarget.toString(),
                            Toast.LENGTH_LONG).show();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
    
                } catch (IOException e) {
                    e.printStackTrace();
                }
                camera.startPreview();
            }
        };
    
    
    
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            if(previewing){
                camera.stopPreview();
                previewing = false;
            }
            if (camera != null){
                try {
                    camera.setPreviewDisplay(surfaceHolder);
                    camera.startPreview();
                    previewing = true;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            camera = Camera.open();
            try {
                camera.setPreviewDisplay(holder);
            } catch (IOException exception) {
                camera.release();
                camera = null;
            }
        }
    
    
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            camera.stopPreview();
            camera.release();
            camera = null;
            previewing = false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Description I have an activity which displays the camera preview on a surface view.
I have a App which uses the camera to take a picture. The camera
I have to detect a face without opening camera Ui or surface view. like
I am developing a game.I have drawn images on a surface view which is
I'm working on this surface project where we have a bing maps control and
Greeting, I have taken a canvas by using Surface View .and i am moving
I am trying to create a surface view for a camera so it renders
I have a class that extends GLSurfaceView. I have handled keyevents for this surface
I have recently built an application that shows you a camera preview on screen.
I'm trying to create moving text.I have crated surface view and thread for looping

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.