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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:54:54+00:00 2026-05-28T07:54:54+00:00

I am trying to change the alpha value of a bitmap per pixel in

  • 0

I am trying to change the alpha value of a bitmap per pixel in a for loop. The Bitmap is created from a createBitmap(source,x,y,w,h) of another bitmap. I’ve done a little test but I can’t seem to alter the alpha. Is it the setPixel command or the fact the bitmap it isn’t ARGB?

I want to create a simple fade out effect in the end but for now I am not referencing original pixel colors just green with half alpha. Thanks if you can help 🙂

        _left[1] = Bitmap.createBitmap(TestActivity.photo, 0, 0, 256, 256);


        for (int i = 0; i < _left[1].getWidth(); i++)
            for (int t = 0; t < _left[1].getHeight(); t++) {

                int a = (_left[1].getWidth() / 2) - i;
                int b = (_left[1].getHeight() / 2) - t;
                double dist = Math.sqrt((a*a) + (b*b));

                if (dist > 20) _left[1].setPixel(i, t, Color.argb(128, 0, 255, 0)); 

            }

UPDATE :

Okay this is the result I came up with if anyone wants to take a bitmap and fade out radially. But yes it is VERY SLOW without arrays… Thanks Reuben for a step in the right direction

public void fadeBitmap (Bitmap input, double fadeStartPercent, double fadeEndPercent, Bitmap output) {

    Bitmap tempalpha = Bitmap.createBitmap(input.getWidth(), input.getHeight(), Bitmap.Config.ARGB_8888 );

    Canvas printcanvas = new Canvas(output);

    int radius = input.getWidth() / 2;
    double fadelength = (radius * (fadeEndPercent / 100));
    double fadestart = (radius * (fadeStartPercent / 100));

    for (int i = 0; i < input.getWidth(); i++)
        for (int t = 0; t < input.getHeight(); t++) {

            int a = (input.getWidth() / 2) - i;
            int b = (input.getHeight() / 2) - t;
            double dist = Math.sqrt((a*a) + (b*b));

            if (dist <= fadestart) {
                tempalpha.setPixel(i,t,Color.argb(255, 255, 255, 255));
            } else {
                int fadeoff = 255 - (int) ((dist - fadestart) * (255/(fadelength - fadestart)));
                if (dist > radius * (fadeEndPercent / 100)) fadeoff = 0;
                tempalpha.setPixel(i,t,Color.argb(fadeoff, 255, 255, 255));
            }

        }

    Paint alphaP = new Paint();
    alphaP.setAntiAlias(true);
    alphaP.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

//  printcanvas.setBitmap();
    printcanvas.drawBitmap(input, 0, 0, null);
    printcanvas.drawBitmap(tempalpha, 0, 0, alphaP);

}
  • 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-28T07:54:54+00:00Added an answer on May 28, 2026 at 7:54 am

    The version of Bitmap.createBitmap() you are using returns an immutable bitmap. Bitmap.setPixel() will have no effect.

    setPixel is appallingly slow anyway. Aim to use setPixels(), or, best of all, find a better way than manipulating bitmap pixels directly. I expect you could do something clever with a separate alpha-only bitmap and the right PorterDuff mode.

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

Sidebar

Related Questions

a newbie question. I'm trying to change an alpha value of a bitmap item
i am trying to incrementally change the alpha value of an OvalShape().. for this
Ive been trying to get my app to change from one scene to another.
I am trying to create an animation effect where an image who's alpha value
i'm trying to dim the alpha channel of individual pixels in a bitmap. i'd
I'm trying to switch our mobile site from the jQuery Mobile Alpha to the
I'm trying change an input mask for textbox when the the check box has
I´m trying to change a spring jsp example to use freemarker. I changed all
im trying to change font globally for whole application, the problem is, i am
I am trying to change the bindingRedirect element at install time by using 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.