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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:28:08+00:00 2026-06-05T20:28:08+00:00

I was following some Java code to do image processing on bitmaps and found

  • 0

I was following some Java code to do image processing on bitmaps
and found that it was really time consuming for the user.

How could this be done faster in code?

Right now it’s taking too long pixel by pixel

I read somewhere about storing it into an 2d array first? Matrix?

public static Bitmap createContrast(Bitmap src, double value) {
    // image size
    int width = src.getWidth();
    int height = src.getHeight();
    // create output bitmap
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
    // color information
    int A, R, G, B;
    int pixel;
    // get contrast value
    double contrast = Math.pow((100 + value) / 100, 2);

    // scan through all pixels
    for(int x = 0; x < width; ++x) {
        for(int y = 0; y < height; ++y) {
            // get pixel color
            pixel = src.getPixel(x, y);
            A = Color.alpha(pixel);
            // apply filter contrast for every channel R, G, B
            R = Color.red(pixel);
            R = (int)(((((R / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
            if(R < 0) { R = 0; }
            else if(R > 255) { R = 255; }

            G = Color.red(pixel);
            G = (int)(((((G / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
            if(G < 0) { G = 0; }
            else if(G > 255) { G = 255; }

            B = Color.red(pixel);
            B = (int)(((((B / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
            if(B < 0) { B = 0; }
            else if(B > 255) { B = 255; }

            // set new pixel color to output bitmap
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }

    // return final image
    return bmOut;
}
  • 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-05T20:28:09+00:00Added an answer on June 5, 2026 at 8:28 pm

    I propose using getPixels and setPixels so that you can manipulate the array directly. I haven’t run this, but it should give you the idea:

    int[] pixels = new int[width * height];
    bmOut.getPixels(pixels, 0, width, 0, 0, width, height);
    // scan through all pixels
    for(int i = 0; i < width * height; i++) {
        // get pixel color
        // pixel = src.getPixel(x, y);
        pixel = pixels[i];
        A = Color.alpha(pixel);
        // apply filter contrast for every channel R, G, B
        R = Color.red(pixel);
        R = (int)(((((R / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
        if(R < 0) { R = 0; }
        else if(R > 255) { R = 255; }
    
        G = Color.green(pixel);
        G = (int)(((((G / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
        if(G < 0) { G = 0; }
        else if(G > 255) { G = 255; }
    
        B = Color.blue(pixel);
        B = (int)(((((B / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
        if(B < 0) { B = 0; }
        else if(B > 255) { B = 255; }
    
        // set new pixel color to output bitmap
        pixels[i] = Color.argb(A, R, G, B);
    }
    bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across some Java code that has a method containing the following: static
I am trying to post some java code snippets on wordpress.com using the following
I'm looking at some Java classes that have the following form: public abstract class
Loading the image one time works as done in the following steps (for code
So I am taking a digital image processing class that requires implementing some image
I am porting some Java code that worked fine on my desktop to Android.
i am new to java, and would like some advice on the following i
I tried following some of the code from here and here , but I
I keep getting some weird error in Processing, using the following tiny piece of
In some Java code running on Windows, I'm reading some large blocks of RGB

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.