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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:23:03+00:00 2026-05-23T22:23:03+00:00

In my app, I was able to run a code using the camera class

  • 0

In my app, I was able to run a code using the camera class to take pictures, but it gives me 2048 x 1536 pixels as the image size.

When I use the default camera of my android device, it gives me 2048 x 1232 pixels as the image size.

Now, the question is, how can I make my app to give me the same image size like the default camera (which is 2048 x 1232) when I take picture?

I have these codes:

CameraActivity.java

public class CameraActivity extends Activity {
    private static final String TAG = "CameraDemo";
    Preview preview; // <1>
    FrameLayout buttonClick; // <2>

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.camera);

        Toast.makeText(getBaseContext(), "Touch the screen to take picture.", Toast.LENGTH_SHORT).show();

        preview = new Preview(this); // <3>
        ((FrameLayout) findViewById(R.id.preview)).addView(preview); // <4>

        //buttonClick = (Button) findViewById(R.id.buttonClick);

        buttonClick = (FrameLayout) findViewById(R.id.preview);

        buttonClick.setOnClickListener(new OnClickListener() {
            public void onClick(View v) { // <5>
                preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
            }
        });

        Log.d(TAG, "onCreate'd");
    }

    // Called when shutter is opened
    ShutterCallback shutterCallback = new ShutterCallback() { // <6>
        public void onShutter() {
            Log.d(TAG, "onShutter'd");
        }
    };

    //Handles data for raw picture
    PictureCallback rawCallback = new PictureCallback() { // <7>
        public void onPictureTaken(byte[] data, Camera camera) {
            Log.d(TAG, "onPictureTaken - raw");
        }
    };


    // Handles data for jpeg picture
    PictureCallback jpegCallback = new PictureCallback() { // <8>
        public void onPictureTaken(byte[] data, Camera camera) {


            FileOutputStream outStream = null;
            try {

                //Write to SD Card
                outStream = new FileOutputStream(
                    String.format(
                            Environment.getExternalStorageDirectory() + "/Engagia/AudienceImages/" + CameraActivity.this.sessionNumber + ".jpg",
                            System.currentTimeMillis()
                    )); // <9>

                outStream.write(data);
                outStream.close();

                Toast.makeText(getBaseContext(), "Preview", Toast.LENGTH_SHORT).show();


                Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
            } catch (FileNotFoundException e) { // <10>
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {

            }
            Log.d(TAG, "onPictureTaken - jpeg");
        }
    };
}

Preview.java

package com.first.Engagia;

import java.io.IOException;

import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

class Preview extends SurfaceView implements SurfaceHolder.Callback { // <1>
    private static final String TAG = "Preview";

    SurfaceHolder mHolder;  // <2>
    public Camera camera; // <3>

    Preview(Context context) {
        super(context);

        // Install a SurfaceHolder.Callback so we get notified when the
        // underlying surface is created and destroyed.
        mHolder = getHolder();  // <4>
        mHolder.addCallback(this);  // <5>
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // <6>
    }


    //Called once the holder is ready
    public void surfaceCreated(SurfaceHolder holder) {  // <7>
        // The Surface has been created, acquire the camera and tell it where
        // to draw.
        camera = Camera.open(); // <8>
        try {
            camera.setPreviewDisplay(holder);  // <9>

            camera.setPreviewCallback(new PreviewCallback() { // <10>

                // Called for each frame previewed
                public void onPreviewFrame(byte[] data, Camera camera) {  // <11>
                    Log.d(TAG, "onPreviewFrame called at: " + System.currentTimeMillis());
                    Preview.this.invalidate();  // <12>
                }

            });
        } catch (IOException e) { // <13>
            e.printStackTrace();
        }
    }

  // Called when the holder is destroyed
  public void surfaceDestroyed(SurfaceHolder holder) {  // <14>
    camera.stopPreview();
    camera = null;
  }

  // Called when holder has changed
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { // <15>
    camera.startPreview();
  }

}

Main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview" 
android:layout_width="match_parent"
android:layout_height="match_parent" >

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/buttonClick"
android:text="Click"
android:layout_gravity="right|bottom" />

</FrameLayout>
  • 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-23T22:23:05+00:00Added an answer on May 23, 2026 at 10:23 pm

    You can use setPictureSize() on the camera parameters object to configure the size of the capture:

    http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setPictureSize(int, int)

    Generally speaking first you should call getSupportedPictureSizes() to make sure you’re asking for a resolution that the hardware supports, but sounds like you already know the sizes.

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

Sidebar

Related Questions

I am able to run a code to take pictures but the resulting image
I'm using the code below. My app was able to draw on the canvas
I am not able to run demo app as given on http://code.google.com/googleapps/marketplace/tutorial_php.html It throws
I really want to be able to have a way to take an app
When I run this code on my computer with the help of Google App
iam using mediaplayercontroller in iphone and in this i am able to run video
i was able to send an MMS using DK's code sample from here and
I'm using uwsgi on Nginx to run some Python code. I'd like to bind
I am trying to run to Android code using an AsyncTask . However it
I'm writing some excel-like C++ console app for homework. My app should be able

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.