2

I get #AARRGGBB color from

int  getColor=bitmap.getPixel()

(Bitmap is ARGB_8888)

As example, getColor value is: #20000000(light grey) I need to get same color in #RRGGBB, something like #BDBDBD(light grey).

How can I do this?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Lokie
  • 23
  • 1
  • 5
  • 1
    #20000000 is black, not light grey. It may become light grey if drawn on top of white since it's translucent. Is that what you want? Get the result of the color drawn on top of white? – Sami Kuhmonen Feb 12 '17 at 07:05
  • Oh, i know it is black color #000000. But is there some way to get exactly color(the color what i see) in #rrggbb, without alpha, or its unreal? – Lokie Feb 12 '17 at 07:25
  • Depends on what you mean by what you see. As I said, if it's on top of white you see one thing. On top of black you see black. By itself it's always black. If you want on top of white then just blend it with white based on alpha. – Sami Kuhmonen Feb 12 '17 at 07:27

2 Answers2

1

If you want the color that would appear when placing that color on top of white you have to blend it. Since alpha is 0x20 you multiply that color by 0x20 and white by 0xff-0x20 and add them up.

Of course do this to R, G and B separately.

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74
  • Sami i am very sorry for bother you, but can you write some example. Maybe some public void colorOnTopOfWhite ( String argbHex), or such like. I study java recently so i need help. Sorry again. – Lokie Feb 12 '17 at 08:37
  • Sorry public String not void – Lokie Feb 12 '17 at 08:37
0

Have a look here: how to change the color of certain pixels in bitmap android

In your case it would be

  for (int i=0; i<myBitmap.getWidth()*5; i++)
      pixels[i] = 0xFFBDBDBD;

The 32 bit integer starts with 0xFF=255 for the alpha value to provide 100% opacity.

Community
  • 1
  • 1
Martin G
  • 229
  • 1
  • 6