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

The Archive Base Latest Questions

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

Using resources from StackOverflow and other helpful websites, I was successful in creating an

  • 0

Using resources from StackOverflow and other helpful websites, I was successful in creating an application that can upload an image taken by the camera application on an Android phone. The only trouble is, the phone I have right now takes very high-quality pictures, resulting in a long wait-time for uploads.

I read about converting images from jpeg to a lower rate (smaller size or just web-friendly sizes), but the code I am using right now saves the captured image as a byte (see code below). Is there any way to reduce the quality of the image in the form that it is in, or do I need to find a way to convert it back to jpeg, reduce the image quality, and then place it back in byte form?

Here is the code snippet I’m working with:

    if (Intent.ACTION_SEND.equals(action)) {

        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            try {

                // Get resource path from intent callee
                Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);

                // Query gallery for camera picture via
                // Android ContentResolver interface
                ContentResolver cr = getContentResolver();
                InputStream is = cr.openInputStream(uri);
                // Get binary bytes for encode
                byte[] data = getBytesFromFile(is);

                // base 64 encode for text transmission (HTTP)
                int flags = 1;
                byte[] encoded_data = Base64.encode(data, flags);
                // byte[] encoded_data = Base64.encodeBase64(data);
                String image_str = new String(encoded_data); // convert to
                                                                // string

                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

                nameValuePairs.add(new BasicNameValuePair("image",
                        image_str));

                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(
                        "http://xxxxx.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                String the_string_response = convertResponseToString(response);
                Toast.makeText(UploadImage.this,
                        "Response " + the_string_response,
                        Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                Toast.makeText(UploadImage.this, "ERROR " + e.getMessage(),
                        Toast.LENGTH_LONG).show();
                System.out.println("Error in http connection "
                        + e.toString());
            }
        }
    }
}
  • 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-15T19:30:59+00:00Added an answer on June 15, 2026 at 7:30 pm

    For web apps, you definitely don’t need the 5+ MP images that cameras produce; image resolution is the primary factor in image size, so I’d suggest you use the BitmapFactory class to produce a downsampled bitmap.

    Particularly, look at BitmapFactory.decodeByteArray(), and pass it a BitmapFactory.Options parameter indicating you want a downsampled bitmap.

    // your bitmap data
    byte[] rawBytes = .......... ;
    
    // downsample factor
    options.inSampleSize = 4;  // downsample factor (16 pixels -> 1 pixel)
    
    // Decode bitmap with inSampleSize set
    return BitmapFactory.decodeByteArray(rawBytes, 0, rawBytes.length, options);
    

    For more info, take a look at the Android Training lesson on displaying bitmaps efficiently and the reference for BitmapFactory:

    http://developer.android.com/training/displaying-bitmaps/index.html

    http://developer.android.com/reference/android/graphics/BitmapFactory.html

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

Sidebar

Related Questions

I'm using two functions one is from this site http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/ and its using function
I am using a DataGrid from the WpfToolkit. I have taken the Style resource
Without using the Graphic Resources how can I create and build up a CTabCtrl?
I'm using the Chart control from the DataVisualization library, and want to use image
We are working an algorithm that calculate the optimal way to move resources from
I know it's a hot question that need anwsers ^^ From my viewpoint, using
I am using http://java.sun.com/jsp/jstl/fmt tag library for outputting messages from Message Resource Bundle which
I am trying to add TableLayout to the LinearLayout from resourse(xml) using programmable way.
I have project asp.net with namespace test and I'm using resources (files Resource.resx and
I'm using the Resources plugin in Grails 2.0.1. The issue I'm having is getting

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.