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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:43:20+00:00 2026-06-15T17:43:20+00:00

Create a bitmap using Bitmap.create(25, 25, Config.ARGB_8888) Setting a pixel with an alpha value

  • 0

Create a bitmap using Bitmap.create(25, 25, Config.ARGB_8888)

Setting a pixel with an alpha value less than or equal to 0xA9 results in the pixel not being set with what’s passed in. I read another stack overflow question saying to setHasAlpha(true), which I did in my test — but that still didn’t fix the issue.

Here’s my android test case showing my issue:

    public void testSettingBitmaps() {
    Bitmap bitmap = Bitmap.createBitmap(25, 25, Config.ARGB_8888);
    bitmap.setHasAlpha(true);

    int color = 0x00fefefe;
    int x= 0;
    int y = 0;

    for(int alpha = 0xFF000000; alpha != 0x00000000; alpha = alpha - 0x01000000) {
        int colorPlusAlpha = color + alpha;
        bitmap.setPixel(x, y, colorPlusAlpha);  

        //
        // This test succeeds if the bitmap let us set the pixel.
        //
        assertEquals(String.format("Current alpha value: %x, Expected pixel value: %x, Actual pixel value: %x", alpha, colorPlusAlpha, bitmap.getPixel(x, y)), 
                colorPlusAlpha, bitmap.getPixel(x, y)); 

    }
}

This code fails with the following output:junit.framework.AssertionFailedError: Current alpha value: a9000000, Expected pixel value: a9fefefe, Actual pixel value: a9fdfdfd expected:<-1442906370> but was:<-1442972163>

  • 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-15T17:43:21+00:00Added an answer on June 15, 2026 at 5:43 pm

    This actually works as intended.

    The problem is that Bitmaps are stored in premultiplied alpha format. This means that when you set a pixel value to 0xa9fefefe, the stored value is actually 0xa9a8a8a8 (0xa9*0xfe/255=0xa8.) Then when you call getPixel(), the stored value is “un-premultiplied.” With rounding errors you get 0xa9fdfdfd.

    Here is a breakdown, you pass an ARGB value of 0xa9fefefe. Each RGB byte will be multiplied by the alpha value before being stored. To simplify we’ll look at the red byte only:

    R=169*254/255
    R=168 (or 0xa8)

    Then when you call getPixel(), the RGB bytes are divided by the alpha:

    R=255*168/169
    R=253 (or 0xfd)

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

Sidebar

Related Questions

Someone can give me short explanation how to create bitmap runtime using GDI/GDI+ and
I'm using Visual Studio to create my installation package. My application use some bitmap
How I can create bitmap image from xaml control using WritableBitmapEx. In my winRT
I'm using android 3.0 and I try to create bitmap xml that will create
I am writing a bitmap file using python. My code to create the bitmap
I want to draw a bitmap into buffer and create a bitmap using javascript.
I am trying to dynamically create a Bitmap Image using byte array using following
I am trying to create a new bitmap file using C. This is a
I create a bitmap from bytes coming via the web and when I downsample
I'm creating an Android application that requires me to create a bitmap of 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.