Android Opengl ES 物体边缘的暗像素

发布于 2024-10-05 06:39:03 字数 1163 浏览 0 评论 0原文

我想提请您注意以下图片

首先是原始图像

alt text

然后它是如何在屏幕上呈现的

< img src="https://i.sstatic.net/BPNUE.png" alt="alt text">

正如您在原始版本中看到的那样,一切都很好,呈黄色,边缘有轻微的透明度,看起来很光滑。

但是当我渲染时,会出现一些变暗的像素。

为了避免我得到的通常答案,

我使用

gl.glTexImage2D(GL10.GL_TEXTURE_2D, level, GL10.GL_RGBA, width, height, 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixelBuffer);

而不是 glutil 工具

gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

有人有解决方案吗

谢谢杰森

编辑


做了一些挖掘。在原始图像中,我的背景已经与硬币的颜色相同,并且我使用了 alpha 蒙版。 我还检查过,当我加载位图时,似乎所有具有 alpha 0 的位图都会自动设置为 0,0,0,0。这可能就是问题所在。


编辑 实际上这似乎是问题所在。我检查了我打开的位图的值,透明像素的值是 0,0,0,0 而不是我设置的颜色。这是位图的问题还是我创建图像的方式的问题?

// Load up, and flip the texture:
            Bitmap temp = BitmapFactory.decodeResource(context.getResources(), resource, opts);
            Bitmap bmp = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), flip, true);
            temp.recycle();

I would like to draw you attention to the following pictures

First the original image

alt text

then how it is rendered on the screen

alt text

as you can see on the original everything is nice and yellow, the edges have a slight transparency to look smooth.

but when I render I have some darkened pixels that appear.

To avoid the usual answer I get

I use

gl.glTexImage2D(GL10.GL_TEXTURE_2D, level, GL10.GL_RGBA, width, height, 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixelBuffer);

and not the glutil tool

also

gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

Anybody has a solution for that ?

Thanks

Jason


Edit

I did some digging. in the original image my background is already the same color as the coin and I use an alpha mask.
I've also checked, when I load the bitmap it seems that all the bitmap who have an alpha 0 are automatically set to 0,0,0,0. this might be the problem.


edit
actually it seems to be the issue. I checked the values of the bitmap I open, the values for transparent pixels are 0,0,0,0 instead of the color I set. Is this a problem with Bitmap or how I created my image?

// Load up, and flip the texture:
            Bitmap temp = BitmapFactory.decodeResource(context.getResources(), resource, opts);
            Bitmap bmp = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), flip, true);
            temp.recycle();

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

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

发布评论

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

评论(2

烟沫凡尘 2024-10-12 06:39:03

您的图像的背景颜色是什么?即当你删除 Alpha 通道时,它会是什么样子?我猜——它是黑色的?尝试将背景颜色设置为与徽标相同的颜色(即淡黄色),然后重试。

编辑:也可以根据评论编辑答案。即使您正确设置了周围像素的 RGB 颜色,某些图像压缩格式仍然可能会对其进行“优化”,并将所有完全透明的像素变成 (0,0,0,0),这将导致您在使用时描述的问题双线性过滤。尝试使用不同的文件格式,或者研究一下是否可以在特定压缩中关闭此功能,或者考虑在加载后修复代码中的图像。

What is the background color of your image? i.e. what does it look like when you remove the alpha channel? I'll guess - it's black? Try giving the background color the same color as your logo (i.e. yellowish) and try again.

EDIT: May as well edit the answer based on the comments. Even if you properly set the RGB color of the surrounding pixels, some image compression formats might still "optimize" that out and turn all completely transparent pixels into (0,0,0,0), which will cause the problems you describe when using bilinear filtering. Try using a different file format, or do research to see if you can turn this feature off in that particular compression, or consider fixing up the image in code after loading.

乖乖哒 2024-10-12 06:39:03

您的图像可能具有预乘的 alpha 值。尝试使用 gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);

请参阅 这篇文章了解更多详情。

Your image probably has premultipled alpha values. Try using gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);

See this post for more details.

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