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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:50:22+00:00 2026-05-31T00:50:22+00:00

I got a problem, where I am stuck now for a long time, I

  • 0

I got a problem, where I am stuck now for a long time, I hope you guys can help me out.
I got a piece of code that I can open an image, change the saturation (with seekbar). then I want to save the changed image. But that last part isn’t working as it should be.

With this code, I can change saturation, and then save the changed bitmap, but it saves the bitmap with the size of the ImageView (480 x 517) however he does apply the saturation change (that is good)

ColorMatrix cm = new ColorMatrix();

System.out.println(progress2);
cm.setSaturation(progress2);
ColorFilter = new ColorMatrixColorFilter(cm);
bitmap_image = BitmapFactory.decodeFile(filePath);
ImageView img = (ImageView) findViewById(R.id.gallery1);
img.setColorFilter(ColorFilter);
img.setImageBitmap(bitmap_image);
img.buildDrawingCache(true);
img.setDrawingCacheEnabled(true);
Bitmap b = img.getDrawingCache();


Bitmap resizedBitmap = Bitmap.createBitmap(bitmap_image, 0, 0, 3264, 2448);
File file = new File(sdcard+"/DCIM/Camera/image3.jpg");
try {
    file.createNewFile();
    FileOutputStream ostream = new FileOutputStream(file);
    **b.compress(CompressFormat.JPEG, 100, ostream);**
    ostream.close();
} catch (Exception e) 
            {
            System.out.println("WRITING HAS FAILED");
            e.printStackTrace();
            }

And the next code, I can also change the saturation, but when I save the bitmap, it does save the bitmap with the original height and width (3264 x 2448) but it doesn’t save the saturation change.

   ColorMatrix cm = new ColorMatrix();

System.out.println(progress2);
cm.setSaturation(progress2);
ColorFilter = new ColorMatrixColorFilter(cm);
bitmap_image = BitmapFactory.decodeFile(filePath);
ImageView img = (ImageView) findViewById(R.id.gallery1);
img.setColorFilter(ColorFilter);
img.setImageBitmap(bitmap_image);
img.buildDrawingCache(true);
img.setDrawingCacheEnabled(true);
Bitmap b = img.getDrawingCache();


Bitmap resizedBitmap = Bitmap.createBitmap(bitmap_image, 0, 0, 3264, 2448);
File file = new File(sdcard+"/DCIM/Camera/image3.jpg");
try {
    file.createNewFile();
    FileOutputStream ostream = new FileOutputStream(file);
    **resizedBitmap.compress(CompressFormat.JPEG, 100, ostream);**
    ostream.close();
    } catch (Exception e) 
        {
        System.out.println("WRITING HAS FAILED");
        e.printStackTrace();
        }

But what I need is that it saves the saturation changes (code 1) and keeps the original width – height (code 2), but somehow I don’t seem to get those 2 codes work together.

Please put me in the good direction.
Code is maybe a mess, tried a lot of things and the structure isn’t getting better of it.

**code** that is the line that changed.

EDIT:
When I do this: (suggestion of Ricki)

Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, 3264, 2448);

I get this error log:

03-09 15:03:02.880: E/AndroidRuntime(847): FATAL EXCEPTION: main
03-09 15:03:02.880: E/AndroidRuntime(847): java.lang.NullPointerException
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.graphics.Bitmap.createBitmap(Bitmap.java:409)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.graphics.Bitmap.createBitmap(Bitmap.java:383)
03-09 15:03:02.880: E/AndroidRuntime(847):  at com.dlv.groenmeter.GroenMeterActivity$13.onStopTrackingTouch(GroenMeterActivity.java:937)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.widget.SeekBar.onStopTrackingTouch(SeekBar.java:115)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:303)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.view.View.dispatchTouchEvent(View.java:3938)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 15:03:02.880: E/AndroidRuntime(847):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1730)
03-09 15:03:02.880: E/AndroidRuntime(847):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1142)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.app.Activity.dispatchTouchEvent(Activity.java:2102)
03-09 15:03:02.880: E/AndroidRuntime(847):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1714)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2218)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1889)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.os.Looper.loop(Looper.java:123)
03-09 15:03:02.880: E/AndroidRuntime(847):  at android.app.ActivityThread.main(ActivityThread.java:3691)
03-09 15:03:02.880: E/AndroidRuntime(847):  at java.lang.reflect.Method.invokeNative(Native Method)
03-09 15:03:02.880: E/AndroidRuntime(847):  at java.lang.reflect.Method.invoke(Method.java:507)
03-09 15:03:02.880: E/AndroidRuntime(847):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
03-09 15:03:02.880: E/AndroidRuntime(847):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
03-09 15:03:02.880: E/AndroidRuntime(847):  at dalvik.system.NativeStart.main(Native Method)
  • 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-31T00:50:23+00:00Added an answer on May 31, 2026 at 12:50 am

    There are 2 problems with the 2nd code:

    1)
    Your saturated image is b so resizedBitmap should be created from that like this:

    Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, 3264, 2448);
    

    2)
    You enable DrawingCache after you build:

    img.buildDrawingCache(true);
    img.setDrawingCacheEnabled(true);
    

    It should be in reverse order:

    img.setDrawingCacheEnabled(true);
    img.buildDrawingCache(true);
    

    EDIT:

    Try this code to set the saturation:

        Bitmap bmp = BitmapFactory.decodeFile(filePath);
        Bitmap alteredBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
        Canvas canvas = new Canvas(alteredBitmap);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(progress2);
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        Matrix matrix = new Matrix();
        canvas.drawBitmap(bmp, matrix, paint);
    
    Bitmap resizedBitmap = Bitmap.createBitmap(alteredBitmap, 0, 0, 3264, 2448);
    File file = new File(sdcard+"/DCIM/Camera/image3.jpg");
    try {
        file.createNewFile();
        FileOutputStream ostream = new FileOutputStream(file);
        resizedBitmap.compress(CompressFormat.JPEG, 100, ostream);
        ostream.close();
        } catch (Exception e) 
            {
            System.out.println("WRITING HAS FAILED");
            e.printStackTrace();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got problem with my code and hopefully someone able to figure it out.
Hi I have got a problem that I can't solve when compiling the android
I have an assignment problem that i can't manage to fix and got totally
I am working on a problem and got stuck at a wall I have
I got stuck in this problem for an hour. I am thinking this is
I've got stuck in a problem with gflags when trying to find some memory
i'm now stuck on this problem for days and i haven't been able to
I am trying to implement the GJK-algorithm but I got stuck instantly. The problem
I got stuck with an approach that the team and I am trying to
I am stuck with this problem for a while now and I am hoping

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.