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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:24:43+00:00 2026-05-30T10:24:43+00:00

I am trying to display a bitmap image pixel by pixel (which explicitly means

  • 0

I am trying to display a bitmap image pixel by pixel (which explicitly means with some delay).
For that I am using two "for-loops", but it prints only a single row of pixels…

My code:

Button start = (Button) findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //Toast.makeText(getBaseContext(), "Printing...", Toast.LENGTH_SHORT).show();
        iImageArray = new int[bMap.getWidth()* bMap.getHeight()];                                   //initializing the array for the image size
        bMap.getPixels(iImageArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());   //copy pixel data from the Bitmap into the 'intArray' array  
             
        //Canvas canvas = new Canvas (bMap);
        //replace the red pixels with yellow ones  
        for (int i=0; i < bMap.getHeight(); i++) {  
            for(int j=0; j<bMap.getWidth(); j++) {
                iImageArray[j] = 0xFFFFFFFF;
            } 
        } 
        bMap = Bitmap.createBitmap(iImageArray, bMap.getWidth(), bMap.getHeight(), Bitmap.Config.ARGB_8888);//Initialize the bitmap, with the replaced color
        image.setImageBitmap(bMap);
        //canvas.drawPoints(iImageArray, 0, bMap.getHeight()*bMap.getWidth(), paint);
    }
});

And I want to print the bitmap in grayscale and for that I found this code…

public Bitmap toGrayscale(Bitmap bmpOriginal) {        
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();    

    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);

    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);

    c.drawBitmap(bmpOriginal, 0, 0, paint);

    return bmpGrayscale;
}

It is iImageArray[i] = 0xFFFFFFFF; that I have to test, not the actual grayscale value…

  • 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-30T10:24:45+00:00Added an answer on May 30, 2026 at 10:24 am

    Your code looks basically correct except for your inner loop. Your comment says that you’re setting them to yellow, but you’re actually storing white. The loop will only affect the first row of pixels because your array index has a range of 0 to width-1. You can either calculate the index by multiplying (i*width+j) or keep a counter that increments.

    Original Version:

    //replace the red pixels with yellow ones  
    for (int i=0; i < bMap.getHeight(); i++)  
    {  
        for(int j=0; j<bMap.getWidth(); j++)
        {
            iImageArray[j] = 0xFFFFFFFF;
        } 
    } 
    

    Fixed Version:

    //replace the red pixels with yellow ones
    int iWidth = bMap.getWidth();  
    for (int i=0; i < bMap.getHeight(); i++)  
    {  
        for(int j=0; j<bMap.getWidth(); j++)
        {
            iImageArray[(i*iWidth)+j] = 0xFF00FFFF; // actual value of yellow
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to extract the palette from a 5-6-5 (16bit) bitmap image that
i am trying to display an image from net..and i am using ignition library
I am trying to display an image using ImageView in Android. The image data
i am trying to display image from internet in my imageview. which is raising
I'm trying to draw Arabic text onto a Bitmap for display: Bitmap img =
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I've been trying to display text using a Quartz context, but no matter what
I am trying to display a pie chart that shows sales by company. However
I am trying to manipulate an image using a chain of CIFilters, and then
I am trying to display the list of songs using array adapters. But the

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.