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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:09:55+00:00 2026-05-31T14:09:55+00:00

The image I am using is from a 4×6. So the aspect ratio should

  • 0

The image I am using is from a 4×6. So the aspect ratio should be about .66. When I calculate the aspect ration in my code , I get around .66. However, the height of the displayed image looks squashed. The image only looks right if I set the aspect ratio manually to around .85.

Since setting the aspect ratio manually is not perfect, how can I get the can I keep the height of my image from appearing to be squashed.

public class SpotGameActivity extends Activity {

private Bitmap mBitmap;

/** Called when the activity is first created. */


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dpi2b);
    setContentView(new BitMapView(this, mBitmap));

}

    class BitMapView extends View {
        Bitmap mBitmap = null;

        public BitMapView(Context context, Bitmap bm) {
            super(context);
            mBitmap = bm;
        }

        @Override
        protected void onDraw(Canvas canvas) {
            // called when view is drawn
            Paint paint = new Paint();
            paint.setFilterBitmap(true);
            // The image will be scaled so it will fill the width, and the
            // height will preserve the image’s aspect ration
            float aspectRatio = ((float) mBitmap.getWidth()) / mBitmap.getHeight();
            Rect dest = new Rect(0, 0, this.getWidth(),(int) (this.getHeight() * aspectRatio));

            String AR = Double.toString(aspectRatio);

            //Rect dest = new Rect(0, 0, getWidth(), getHeight());

            canvas.drawBitmap(mBitmap, null, dest, paint);
            Toast.makeText(SpotGameActivity.this, AR, Toast.LENGTH_SHORT).show();   
        }
    }

}

  • 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-31T14:09:56+00:00Added an answer on May 31, 2026 at 2:09 pm

    Aspect = width/height

    newHeight = newWidth/Aspect

    Do this,

    Rect dest = new Rect(0, 0, this.getWidth(),(int) (this.getWidth() / aspectRatio));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to get the perticluar image from large set images in one image using
How do you get a image from the scanner using .NET (C#) on Vista?
I am trying to get an image from an HTTP server using Perl. I
I'm able to save the captured image from a barcode scanner using this code:
I wanted to extract the Signer Informations from PKCS#7 Signed Code Image using C/CPP.
I'm trying to download an image using this code: from urllib import urlretrieve urlretrieve('http://gdimitriou.eu/wp-content/uploads/2008/04/google-image-search.jpg',
Here's the code I'm using: from PIL import Image import ImageFont, ImageDraw import sys
I want to calculate the magnetic field from a given image using biot savarts
I wrote a simple Sinatra app that generate an image using rmagick from some
Apart from using image on the button, how can I write X Y on

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.