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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:42:16+00:00 2026-05-27T07:42:16+00:00

I am uploading an image to a server and before that happens, I would

  • 0

I am uploading an image to a server and before that happens, I would like to resize the image dimensions. I get the image with a URI like this:

Constants.currImageURI = data.getData();

this is the call to upload the image:

String response = uploadUserPhoto(new File(getRealPathFromURI(Constants.currImageURI)));

    public String uploadUserPhoto(File image) {

    DefaultHttpClient mHttpClient;
    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    mHttpClient = new DefaultHttpClient(params);

    try {
        HttpPost httppost = new HttpPost("http://myurl/mobile/image");

        MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);  
        multipartEntity.addPart("userID", new StringBody(Constants.userID));
        multipartEntity.addPart("uniqueMobileID", new StringBody(Constants.uniqueMobileID));
        multipartEntity.addPart("userfile", new FileBody(image, "mobileimage.jpg", "image/jpeg", "UTF-8"));
        httppost.setEntity(multipartEntity);

        HttpResponse response = mHttpClient.execute(httppost);
        String responseBody = EntityUtils.toString(response.getEntity());

        Log.d(TAG, "response: " + responseBody);
        return responseBody;

    } catch (Exception e) {
       Log.d(TAG, e.getMessage());
    }
    return "";
}

Is there a way to resize the file based on pixel dimensions?

Thanks.

  • 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-27T07:42:17+00:00Added an answer on May 27, 2026 at 7:42 am

    This is taken from ThinkAndroid at this url:
    http://thinkandroid.wordpress.com/2009/12/25/resizing-a-bitmap/

    I would look into the possibility of creating a Bitmap or Drawable from the resource and if you want to change it’s size use the code below.

    public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
        int width = bm.getWidth();
        int height = bm.getHeight();
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;
    
        // Create a matrix for the manipulation
        Matrix matrix = new Matrix();
    
        // Resize the bit map
        matrix.postScale(scaleWidth, scaleHeight);
    
        // Recreate the new Bitmap
        Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
        return resizedBitmap;
    
    }
    

    EDIT: As suggested in other comment Bitmap.createScaledBitmap should be used for better quality when resizing.

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

Sidebar

Related Questions

I'm uploading image file to storage server. Before uploading I should compose filename, which
I want to preview an image before uploading it to the server. I have
I am uploading image to server using base64 its working fine if image is
I have an ASPX page where I am uploading an image to server for
In my application I'm uploading an image on to the server. Here in the
I'm working on a project that involves uploading an image to tumblr from Python.
Is there is any method for validating the dimensions of the image file before
Part of my webapp involves uploading image files. On the production server, the files
I have tried uploading a transparent PNG image to a SQL server image field,
I have a loop on the server ( C# ) that does this: for(i=0;i<=Request.Files.Count

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.