当保存为 png 格式时,如果 Alfa=0,为什么 RGB 值会丢失?

发布于 2025-01-19 11:36:36 字数 701 浏览 3 评论 0原文

当我创建位图

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

并使用 Alfa (1-255) 编辑像素

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

并保存到 png

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

时,它可以正常工作。

但如果我尝试使用 Alfa=0 保存,

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

RGB 值也等于 0。

当保存为 png 格式时,如果 Alfa=0,为什么 RGB 值会丢失? 如何修复它?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2025-01-26 11:36:36

当png格式保存时,为什么如果alfa = 0丢失RGB值?如何修复它?

当然,ARGB(0,0,0,0)和argb(0,nothingse)...但是0/0/0/0/0在ARGB(0,0,0,0)之间没有(视觉上的)差异,但是0/0/0/0可以更好地压缩方式,因此PNG保存功能是试图通过抛弃看不见的东西来改善生活。

事实证明,您显然希望保存原本看不见的信息。

我很确定解决方案是将硬质性设置为OFF:

options.inPremultiplied = false;

如果那不起作用,我认为在Android的位图中烤制不可能完成。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文