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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:55:20+00:00 2026-06-04T14:55:20+00:00

This is an Android question: I am taking a jpeg picture taken with the

  • 0

This is an Android question:

I am taking a jpeg picture taken with the camera and resizing it to 640 x 480 resolution after which I add a watermark to the image. This bitmap is then compressed to a jpeg file and saved.

The problem is that the quality of the jpeg is reduced considerable as you can see from the examples below. The first one is the original jpeg taken by the camera and the second one is the resized and watermarked version. You can see the graininess and colour inconsistencies introduced in the final image.

Also as a separate question, is there a way to reduce the size of the final jpeg image? My Samsung phone on 640×480 resolution delivers a jpeg of about 100KB, whereas using the code below I get a final jpeg size of ~250KB. Reducing “Bitmap.CompressFormat.JPEG” quality to 70% does not get me even close to 100KB.

See the code below.

Source image form camera: http://www.freeimagehosting.net/ehtso

Final resized and watermarked image: http://www.freeimagehosting.net/qsxs6

public class AIS_PhotoResize {

//resize photos to reduce data cost for sending photos
public String ResizePhoto(String photoName)
{       
    //folder location for existing photos
    File oldFileRoot = new File(Environment.getExternalStorageDirectory() + File.separator + "AIS_Photos" + File.separator);
    File oldFile = new File(oldFileRoot, photoName);

    //folder location for resized photos
    File newFileRoot = new File(Environment.getExternalStorageDirectory() + File.separator + "AIS_Photos" + File.separator + "Resized" + File.separator);
    //ensure folder exist
    newFileRoot.mkdirs();
    File newFile = new File(newFileRoot, photoName);

    Bitmap b = null;
    try {
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        FileInputStream fis = new FileInputStream(oldFile);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

        //The new size we want to scale to
        final int IMAGE_MAX_SIZE=800;

        int scale = 1;
        if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
            scale = (int)Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
        }

        //Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;     
        o2.inPreferredConfig = Bitmap.Config.ARGB_8888;
        o2.inScaled = false;
        o2.inDither = true;
        fis = new FileInputStream(oldFile);
        b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();

        //scale resized bitmap (version 1 - scaling using createScaledBitmap) 
        int scaledHeight = (int) (640 / ((float)b.getWidth() / (float)b.getHeight()));
        Bitmap bScaled = Bitmap.createScaledBitmap(b, 640, scaledHeight, true);
        b.recycle();

        /*
        //scale resized bitmap (version 2 - scaling using matrix)            
        Matrix matrix = new Matrix();
        float desiredScale = 640 / (float)b.getWidth();
        matrix.postScale(desiredScale, desiredScale);
        Bitmap bScaled = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);
        //b.recycle();
        */

        //add timestamp watermark to photo
        String watermark = photoName.substring(0, photoName.length() - 4);
        Bitmap dest = Bitmap.createBitmap(bScaled.getWidth(), bScaled.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas cs = new Canvas(dest);
        Paint tPaint = new Paint();
        tPaint.setTextSize(15);
        tPaint.setColor(Color.RED);
        tPaint.setStyle(Style.FILL);
        tPaint.setAntiAlias(true);
        Paint bScaledPaint = new Paint();
        bScaledPaint.setDither(true);
        cs.drawBitmap(bScaled, 0f, 0f, bScaledPaint);
        float height = tPaint.measureText("yY");
        cs.drawText(watermark, 5f, height+5f, tPaint);
        bScaled.recycle();

        //encode scaled bitmap to jpeg
        FileOutputStream out = new FileOutputStream(newFile);
        dest.compress(Bitmap.CompressFormat.JPEG, 100, out);

        //cleanup
        dest.recycle();
        out.close();

        return "Success";

    } catch (IOException e) {
        ErrorReporter.getInstance().handleException(e);
        return "Error: " + 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-04T14:55:22+00:00Added an answer on June 4, 2026 at 2:55 pm

    It seems that I am not able to improve the quality of the images, nor am I able to reduce the size and keep the quality in tact. This is the limitations of Android.

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

Sidebar

Related Questions

Similar to this question but for Android: Android GLES20 supports a method glShaderBinary, which,
After reading the android documentation about String, which includes this: This class is implemented
I have a question this time around regarding the Android custom camera, NOT the
I started with this question: Android - RelativeLayout inflated as Button? . It appeared
This is a follow up on the question Android accesing soap service posted by
This is a question concerning android applications with two different .apks (or two apps
This is a related question to: Android NFC start service In Android, can an
This question is about TimePicker behavior in Android. To get the value of the
This question was originally asked for Android 1.6. I am working on photos options
This question occured to me while programming a Android application, but it seems to

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.