当保存为 png 格式时,如果 Alfa=0,为什么 RGB 值会丢失?
当我创建位图
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,ARGB(0,0,0,0)和argb(0,nothingse)...但是0/0/0/0/0在ARGB(0,0,0,0)之间没有(视觉上的)差异,但是0/0/0/0可以更好地压缩方式,因此PNG保存功能是试图通过抛弃看不见的东西来改善生活。
事实证明,您显然希望保存原本看不见的信息。
我很确定解决方案是将硬质性设置为OFF:
如果那不起作用,我认为在Android的位图中烤制不可能完成。
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:
and if that doesn't work, I don't think it can be done with android's baked in BitMap stuff.