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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:19:52+00:00 2026-06-11T10:19:52+00:00

I am trying to render camera preview using SurfaceTexture . I read the document

  • 0

I am trying to render camera preview using SurfaceTexture. I read the document but unable to understand how it works.

Can anyone provide one sample example(very basic one) or link which uses SurfaceTexture to preview camera. I googled this but not found what I am looking for.

Thanks in advance.

  • 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-11T10:19:53+00:00Added an answer on June 11, 2026 at 10:19 am

    If you want to use the Camera with TextureSurface you can implement SurfaceTextureListener interface. You’ll have to implement 4 methods:

    1) onSurfaceTextureAvailable – Here you setup your camera

    2)onSurfaceTextureSizeChanged – In your case, the Android’s camera will handle this method

    3)onSurfaceTextureDestroyed – Here you destroy all camera stuff.

    4) onSurfaceTextureUpdated– Update your texture here when you have something to change!

    Check the example below:

        public class MainActivity extends Activity implements SurfaceTextureListener{
    
        private Camera mCamera;
        private TextureView mTextureView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            mTextureView = new TextureView(this);
            mTextureView.setSurfaceTextureListener(this);
    
            setContentView(mTextureView);
        }
    
        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
            mCamera = Camera.open();
    
            Camera.Size previewSize = mCamera.getParameters().getPreviewSize();
            mTextureView.setLayoutParams(new FrameLayout.LayoutParams(
                    previewSize.width, previewSize.height, Gravity.CENTER));
    
            try {
                mCamera.setPreviewTexture(surface);
            } catch (IOException t) {
            }
    
            mCamera.startPreview();
    
        }
    
        @Override
        public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
            // Ignored, the Camera does all the work for us
        }
    
        @Override
        public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
            mCamera.stopPreview();
            mCamera.release();
            return true;
        }
    
        @Override
        public void onSurfaceTextureUpdated(SurfaceTexture surface) {
            // Update your view here!
        }
    }
    

    Two more things: Don’t forget to add the camera permissions in your project’s manifest and the SurfaceTexture is available from API 11.

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

Sidebar

Related Questions

I'm trying to render some text using PIL, but the result that comes out
i´m trying to render PDF with renderpdf grails plugin, but their documentation is very
I've been trying to render a webpage using the Adobe Flex / Flash builder
I am trying to render a ViewModel using Razor and MVC3. For some reason
I'm trying to render a cube using an array of 8 vertices and an
I am trying to render a very complex model using json file. The size
I'm trying to use gluLookAt to move the camera in my iPhone game, but
I am trying to get shadow mapping working using GLSL. Unfortunately my depth render
I'm trying to render text aligned within the center of a box using imagettftext()
I'm trying the render an HTML list that looks like the following, using the

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.