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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:12:58+00:00 2026-06-13T23:12:58+00:00

I want to display this image and upload it to a server. I’m using

  • 0

I want to display this image and upload it to a server.

I’m using the camera app to take a photo and returning the file path of the photo to an activity. I run into an Out of Memory error on some phones because I have a constant image size that I try and import between devices.

How can I pull in the largest image size possible to upload to the server while still working within the memory constraints of the phone?

Code Follows:

request to load Aync

GetBitmapTask GBT = new GetBitmapTask(dataType, path, 1920, 1920, loader);
GBT.addAsyncTaskListener(new AsyncTaskDone() 
{
    @Override
    public void loaded(Object resp) 
    {               
        crop.setImageBitmap((Bitmap)resp);
        crop.setScaleType(ScaleType.MATRIX);
    }

    @Override
    public void error() {
    }
});

GBT.execute();

The Async Task that throws the OOM error

public class GetBitmapTask extends AsyncTask<Void, Integer, Bitmap> 
{

 ...

@Override
public Bitmap doInBackground(Void... params) 
{
    Bitmap r = null;

    if (_dataType.equals("Unkown"))
    {
        Logger.e(getClass().getName(), "Error: Unkown File Type");
        return null;
    }
    else if (_dataType.equals("File")) 
    {   
        Options options = new Options();            
        options.inJustDecodeBounds = true;

        //Logger.i(getClass().getSimpleName(), _path.substring(7));

        BitmapFactory.decodeFile(_path.substring(7), options);

        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

        Logger.i(getClass().getSimpleName(), 
                "height: " + options.outHeight +
                "\nwidth: " + options.outWidth +
                "\nmimetype: " + options.outMimeType +
                "\nsample size: " + options.inSampleSize);

        options.inJustDecodeBounds = false;
        r = BitmapFactory.decodeFile(_path.substring(7), options);

    } 
    else if (_dataType.equals("Http")) 
    {
        r = _loader.downloadBitmap(_path, reqHeight);

        Logger.i(getClass().getSimpleName(), "height: " + r.getHeight() +
                                            "\nwidth: " + r.getWidth());
    }

    return r;
}

public static int calculateInSampleSize( Options options, int reqWidth, int reqHeight) 
{
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    while (height / inSampleSize > reqHeight || width / inSampleSize > reqWidth) 
    {
        if (height > width)
        {
            inSampleSize = height / reqHeight;
            if (((double)height % (double)reqHeight) != 0) 
            {
                inSampleSize++;
            }
        } 
        else 
        {
            inSampleSize = width / reqWidth;
            if (((double)width % (double)reqWidth) != 0) 
            {
                inSampleSize++;
            }
        }
    }
    return inSampleSize;
}
}
  • 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-13T23:12:59+00:00Added an answer on June 13, 2026 at 11:12 pm

    You can give the camera the uri pointing to file you want to save the image into:

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mDefaultPhotoUri); // set path to image file
    

    You can then upload that file to your server, so you have the full bitmap size. On the other hand, there is no need (and on many devices no way) to decode and show bitmap 1920×1920 (or similar) in UI, it’s just too big.

    Hope this helps.

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

Sidebar

Related Questions

I want to display an image using this php script on my server. $file
This was a question about testing file upload functionality using a local java server
I got this Base64 gif image: R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7 Now I want to display this
In my XAML file I want to display this text which contains double and
I use Windows and I display a file extention. When I upload an image
I want to upload a image to server side and I stored it into
I use codeigniter. I want multiple upload image, for this work, i use library
I'm using an UpdatePanel in ASP.NEt WebForms to upload a image. I want to
I have a map ` { key1=[button1,button2,button3,button4],key2=[button1],key3=[button1,button2],key4=[button1,button2,button3]} ` i want to display this map
I want to display a This page took x seconds widget at the bottom

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.