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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:35:54+00:00 2026-05-22T14:35:54+00:00

This is a simple problem, but I wonder if it has a non-expensive solution.

  • 0

This is a simple problem, but I wonder if it has a non-expensive solution.

I have a gallery view which loads images from memory, either SD card or resources. Their size is 480×800, so the code samples them down and show as thumbnails in a Gallery View. All works fine, kind of…

Some images are landscape while some portrait. The gallery’s imageview layout shows them all as landscape thus all portrait images look badly stretched!

Since these images are abstract drawings I would like to rotate the portrait ones so that they all nicely and evenly fit in the gallery. I could detect their orientation by comparing their width and height and then rotate the portrait ones using Matrix and canvas, but that may be too expensive and slow to run in getView() of a BaseAdapter.

Can anybody think of a less expensive way to do it?

    public View getView(int position, View convertView, ViewGroup parent){   
        ImageView i = new ImageView(mContext);   
        Bitmap bm = null;

        if (mUrls[position] != null){
            bm = BitmapFactory.decodeFile(mUrls[position].toString(),options); 
            if (bm != null){
                //here could use a bitmap rotation code
                //....
                i.setImageBitmap(bm);
            }
        }else{
            bm = BitmapFactory.decodeResource(getResources(), R.drawable.deleted);
            i.setImageBitmap(bm);
        }
        i.setScaleType(ImageView.ScaleType.FIT_XY);   
        i.setLayoutParams(new Gallery.LayoutParams(200, 130)); 
        i.setBackgroundResource(mGalleryItemBackground);
        return i;   
    }

EDIT

After some testing I am using the code below to rotate the image which is not super-fast but it can do at the moment.

int w = bm.getWidth();
int h = bm.getHeight();
if (w < h){
  Matrix matrix = new Matrix(); 
  matrix.postRotate(-90);
  bm = Bitmap.createBitmap(bm, 0, 0, w, h, matrix, false);    
}
i.setImageBitmap(bm);
  • 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-22T14:35:54+00:00Added an answer on May 22, 2026 at 2:35 pm

    Enter the Matrix!!!

    Resize and Rotate Image – Example

    very useful for me, hope it helps

      if (bm != null){
            Matrix matrix = new Matrix();
            matrix.postScale(scaleWidth, scaleHeight);
            matrix.postRotate(45);
            Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true);   
            BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
            i.setImageBitmap(bmd); 
           }
    

    recycling works, i recommend use asynctask to load the images this avoid the UI blocks.

    Heres an example::

    http://android-apps-blog.blogspot.com/2011/04/how-to-use-asynctask-to-load-images-on.html

    another example::

    http://open-pim.com/tmp/LazyList.zip

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

Sidebar

Related Questions

I'm guessing this is a simple problem, but I'm just learning... I have this:
this must be such a simple problem but can someone tell me why this
This may be a very simple problem, but I couldn't find an answer googleing
This is such a simple problem, but I can't find an answer anywhere... I
This one seems to be a simple problem, but I can't make it work
I am sure this is a very simple problem, but I am new to
I've never learnt JavaScript, but I imagine this is quite a simple problem. Just
Ok, this is an embarassingly simple-looking problem, but is driving me crazy. I'm learning
This problem is not readily reproducible in a simple example here but was wondering
This is a big-picture question... but I also have details on the problem I

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.