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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:18:18+00:00 2026-06-01T23:18:18+00:00

I just ran into an issue while trying to write an bitmap-manipulating algo for

  • 0

I just ran into an issue while trying to write an bitmap-manipulating algo for an android device.

I have a 1680×128 pixel Bitmap and need to apply a filter on it. But this very simple code-piece actually took almost 15-20 seconds to run on my Android device (xperia ray with a 1Ghz processor).

So I tried to find the bottleneck and reduced as many code lines as possible and ended up with the loop itself, which took almost the same time to run.

for (int j = 0; j < 128; j++) {
    for (int i = 0; i < 1680; i++) {
         Double test = Math.random();
    }
}

Is it normal for such a device taking so much time in a simple for-loop with no difficult operations?

I’m very new to programming on mobile devices so please excuse if this question may be stupid.

UPDATE: Got it faster now with some simpler operations.

But back to my main problem:

public static void filterImage(Bitmap img, FilterStrategy filter) {
    img.prepareToDraw();
    int height = img.getHeight();
    int width = img.getWidth();
            RGB rgb;
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            rgb = new RGB(img.getPixel(i, j));
            if (filter.isBlack(rgb)) {
                img.setPixel(i, j, 0);
            } else
                img.setPixel(i, j, 0xffffffff);
        }
    }
    return;
}

The code above is what I really need to run faster on the device. (nearly immediate)
Do you see any optimizing potential in it?

RGB is only a class that calculates the red, green and blue value and the filter simply returns true if all three color parts are below 100 or any othe specified value.
Already the loop around img.getPixel(i,j) or setPixel takes 20 or more seconds. Is this such an expensive operation?

  • 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-01T23:18:19+00:00Added an answer on June 1, 2026 at 11:18 pm

    First of all Stephen C makes a good argument: Try to avoid creating a bunch of RGB-objects.

    Second of all, you can make a huge improvement by replacing your relatively expensive calls to getPixel with a single call to getPixels

    I made some quick testing and managed to cut to runtime to about 10%. Try it out. This was the code I used:

    int[] pixels = new int[height * width];
    img.getPixels(pixels, 0, width, 0, 0, width, height);
    
    for(int pixel:pixels) {
        // check the pixel
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've ran into an issue while trying to put together a Grails app with
I just ran into an issue with Python's imaplib and Gmail's authentication mechanism: >>>
I ran into an issue with something that I am probably just overlooking. I
I just ran into a problem.. I'm trying to build a website at the
I am trying to organize my program into functions and have ran into this,
I ran into this issue on accident while debugging a faulty string trim function
I just upgraded to XCode 4.0.2 and ran into a strange issue. Every time
I ran into this interesting issue today. I have a button on a wpf
I just ran into an issue: when I try to access a private or
Just about everyone has ran into this specific issue: function addLinks () { for

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.