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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:58:30+00:00 2026-06-10T19:58:30+00:00

I have the following problem: I have an app with a camera and top

  • 0

I have the following problem: I have an app with a camera and top of it and image as an Overlay. The Image is in 4/3 I get the optimal size for my screen and I draw the Image.
The problem is that I don’t see all the image when I try it. I have the image cutted on top and bottom of the screen. The thing is that if I take a picture then I see the photo perfect

I’m using android sdk 8 and the camera is in landscape mode. In my Samsung galaxy S the overlay and the surfacepreview gives the same size 640:480.

I have been playing for a while and I haven’t found a solution yet.

Here’s the code.

my xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/framecamera"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center"
    android:padding="0dip"
    android:layout_margin="0dip"
>
<FrameLayout
    android:id="@+id/surface"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="0dip"
    android:layout_margin="0dip"
>
</FrameLayout>
<ImageButton
    android:id="@+id/button_capture"
    android:contentDescription="@string/click"
    android:text="@string/click"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center|right"
    android:background="@drawable/camera"
    android:src="@drawable/camera"
/>
</LinearLayout>

the important parts of my code:

setContentView(R.layout.camera);

//create an instance of Camera
mcam = getCameraInstance();
Camera.Parameters parameters=mcam.getParameters();
size=getBestPreviewSize(parameters);//gets the 4/3 size

horizontal = Bitmap.createScaledBitmap(horizontal, size.width, size.height, false);

// Create our Preview view and set it as the content of our activity.
mpreview = new CameraPreview(getBaseContext(), mcam);
FrameLayout frame = (FrameLayout) findViewById(R.id.surface);
SurfaceHolder mSurfaceHolder = mpreview.getHolder();
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

//set our view to 4:3
ViewGroup.LayoutParams params = frame.getLayoutParams();
params.width = size.width;
params.height = size.height;
frame.setLayoutParams(params);

//add the necessary margin to the view
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
MarginLayoutParams ps=(MarginLayoutParams )frame.getLayoutParams();
ps.topMargin = 0;
ps.bottomMargin = 0;
ps.leftMargin = (display.getWidth()-size.width)/2;//to center the overlay
frame.setLayoutParams(ps);

frame.addView(mpreview);

over = new OverlayPreview(getBaseContext(),horizontal);//inside I draw the canvas
frame.addView(over);

Any ideas would be greatly appreciated. I think the problem comes from the padding maybe or the xml but I don’t know how to fix it. Thank you very much.

p.d: Sorry for my english, not my first language.

  • 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-10T19:58:32+00:00Added an answer on June 10, 2026 at 7:58 pm

    ok! I finally found how to do that!

    I changed the way to do it and now i’m using and ImageView for the frame.

    // Create our Preview view
    mpreview = new CameraPreview(getBaseContext(), mcam);
    
    FrameLayout frame = (FrameLayout) findViewById(R.id.surface);
    
    SurfaceHolder mSurfaceHolder = mpreview.getHolder();
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    
    ImageView imageframe = (ImageView) findViewById(R.id.iframe);
    imageframe.setImageBitmap(horizontal);
    
    //set our view to 4:3
    ViewGroup.LayoutParams params = frame.getLayoutParams();
    params.width = size.width;
    params.height = size.height;
    frame.setLayoutParams(params); 
    
    //add the necessary margin to the view
    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    MarginLayoutParams ps=(MarginLayoutParams)frame.getLayoutParams();
    ps.topMargin = 0;
    ps.bottomMargin = 0;
    ps.leftMargin = (int)((display.getWidth()-size.width)/2) + 50;
    ps.rightMargin = (int)((display.getWidth()-size.width)/2) + 50;
    frame.setLayoutParams(ps);
    
    frame.addView(mpreview);
    

    I guess it’s not the best solution to do it but it’s working at least.

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

Sidebar

Related Questions

I have the following problem: My app has a thread that updates the game
I have the following problem: I need to get a ConfigurationSection - object from
I am having the following problem: I have a WCF service that checks a
HI Guys, I have following problem. I'm trying to connect from my Iphone app
I am a new programmer... i have following problem.. Terminating app due to uncaught
I have the following problem. We have build an app with mono for android.
I have the following problem: As our app is going to be shown to
I have a mobile app and I have the following problem. I select some
hi i am in mobile app and i have the following problem. i want
I have the following problem. I got a bat file that runs testcomplete test.

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.