0

when i create Bitmap

Bitmap newBitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);

and edit pixels with Alfa (1-255)

newBitmap.setPixel(0, 0, Color.argb(255, 50, 100, 250));

and save to png

final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inScaled = false;
            FileOutputStream out = new FileOutputStream(photoFile);
            newbitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

it work seccess.

But if i try save with Alfa=0

newBitmap.setPixel(0, 0, Color.argb(0, 50, 100, 250));

RGB value equals 0 too.

Why are RGB values lost if Alfa=0, when saving in png format? How to fix it?

Chego
  • 135
  • 9
  • No, that's not what that means, @JhanzaibHumayun. Alpha=0 is fully transparent; it has no colour (it would mean: Fully adapt the colour of whatever is 'under' the image). – rzwitserloot Apr 06 '22 at 14:13
  • I did not allow the rgb data to be destroyed, I need them for further work. How to prohibit their destruction? – Chego Apr 06 '22 at 14:17

1 Answers1

1

Why are RGB values lost if Alfa=0, when saving in png format? How to fix it?

There is no (visual) difference, of course, between ARGB(0,0,0,0) and ARGB(0,anythingelse)... but 0/0/0/0 compresses way better, so the PNG saving functionality is trying to improve your life by ditching the invisible stuff.

Turns out you are evidently wanting to save the otherwise invisible info.

I'm pretty sure that the solution is to set premultiplication to off:

options.inPremultiplied = false;

and if that doesn't work, I don't think it can be done with android's baked in BitMap stuff.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72