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

The Archive Base Latest Questions

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

I got a little problem, I got a code, that reads all pixels and

  • 0

I got a little problem, I got a code, that reads all pixels and takes the RGB color of the pixel. But before that, I cut the picture into chunks, so I can also calculate larger images, without exceeding memory.
Here is the code:

Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);

            try {
                decoder_image = BitmapRegionDecoder.newInstance(filePath,
                        false);


            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                boolean bool_pixel = true;
                final int width = decoder_image.getWidth();
                final int height = decoder_image.getHeight();
                // Divide the bitmap into 1100x1100 sized chunks and process it.
                // This makes sure that the app will not be "overloaded"
                int wSteps = (int) Math.ceil(width / 1100.0);
                int hSteps = (int) Math.ceil(height / 1100.0);
                Rect rect = new Rect();
                for (int h = 0; h < hSteps; h++) {
                    for (int w = 0; w < wSteps; w++) {
                        int w2 = Math.min(width, (w + 1) * 1100);
                        int h2 = Math.min(height, (h + 1) * 1100);
                        rect.set(w * 1100, h * 1100, w2, h2);
                        bitmap_image = decoder_image.decodeRegion(rect,
                                null);

                        try {
                            int bWidth = bitmap_image.getWidth();
                            int bHeight = bitmap_image.getHeight();
                            int[] pixels = new int[bWidth * bHeight];
                            bitmap_image.getPixels(pixels, 0, bWidth, 0, 0,
                                    bWidth, bHeight);
                            for (int y = 0; y < bHeight; y++) {
                                for (int x = 0; x < bWidth; x++) {

                                    int index = y * bWidth + x;
                                    int R = (pixels[index] >> 16) & 0xff; //bitwise shifting
                                    int G = (pixels[index] >> 8) & 0xff;
                                    int B = pixels[index] & 0xff;
                                    total++;

                                    if (R == 255){
                                    //Save x,y position                                     
                                    }
                                    if ((G > (R+2)) && (G > (B+2))) {
                                    counter++;
                                    }
                                }
                            }
                        } finally {
                            bitmap_image.recycle();
                        }
                    }
                }
            } finally {
                decoder_image.recycle();                    
            }

This works like a charm. Had some info from the internet, and I remade this for my own code.

But what do I want now, that is: when he detects a “full” red pixel (255), he must show the x,y position of that pixel.

I thought this was very easy to do, but because I cut the image into chucks I get very weird x,y positions (what I think).

I will explain fast why I want this: In the image, their are 2 red pixels, and those 2 must be transformed into a rectangle, but I don’t get the good x,y positions.

So to get the question clear: How do I get the x,y location of the red pixel.

Maybe very easy, but somehow I just don’t get the right location, not even close. I check this with opening the image in Photoshop, and look what the x,y of the red pixel is, but my app gives very weird coordinates.

If you need more info or something else, please comment.

Thanks already,
Bigflow

  • 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-01T06:00:47+00:00Added an answer on June 1, 2026 at 6:00 am

    Coords should be rect.left + x and rect.top + y. Have you tried this already?

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

Sidebar

Related Questions

Got a little problem i asked about it before but maybe i didnt ask
I got a little problem. Sometimes, when I try to call the following code,
I've got a little problem that's slightly frustrating. Is it possible to set a
I got a little problem, what I think, can't be hard. but somehow, I
Hey, I've got this nice little piece of code, much like all the other
I'm working on a fairly simple console application but I got one little problem.
i`ve got a little problem with LINQ. I read out some information via XML-RPC.
I've got a little problem with Zend Framework Zend_Pdf class. Multibyte characters are stripped
I've got a little problem using WPF Dispatcher Timer. On each timer tick my
Good evening I've got a little problem with my DataGridView in a .NET Windows

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.