使用 HSV 为灰度精灵着色

发布于 2024-12-12 00:48:11 字数 902 浏览 0 评论 0原文

我正在使用 AndEngine 进行动态壁纸项目,尽管我认为我的问题应该适用于 Android 甚至完全 Java。直到最近,由于缩放优势,我还在图像中使用 SVG,但是由于矢量艺术的图形限制,我决定切换到 PNG,而且我似乎不知道如何获得之前的 HSV 着色正确应用于新精灵。

目前我基本上只是在精灵上添加一些 HSV 值,它在技术上确实有效,但不正确。我似乎根本没有像以前那样真正控制饱和度或值/亮度,它们似乎只有两个级别,就好像它们立即设置为 0.0 或 1.0 一样,尽管颜色本身非常暗,而且显然没有达到全值/亮度和饱和度。

我没有看到我正在做的事情和我为 SVG 图像所做的设置之间有任何真正的区别,所以我有点不知所措。想必在 AndEngine 深处的某个地方还做了其他一些事情来使其一切正常工作,但我只是不知道现在要做什么。我或多或少使用的相关代码是:

        float[] temphsv = new float[3];
        int colorAfter = 0;

        Sprite tempSprite = new Sprite(x, y, 400, 600, mSprite);
        temphsv[0] = 120;
        temphsv[1] = 1.0f;
        temphsv[2] = 1.0f;
        colorAfter = Color.HSVToColor(temphsv);
        tempSprite.setColor(Color.red(colorAfter), Color.green(colorAfter), Color.blue(colorAfter));

从技术上讲,代码现在的方式图像应该只是纯亮绿色,但相反它是相当深的绿色,并且仍然保留其阴影。我想这是一件微不足道的事情,因为它与 SVG 图像配合得很好,所以任何关于我所缺少的内容的提示都会很棒。

I am using AndEngine for a live wallpaper project, though I imagine my problem should be universal to Android or even Java entirely. Until recently I was using SVG's for my images due to the scaling benefits, however because of the graphical limitations of vector art I decided to switch to PNG, and I can't seem to figure out how to get the HSV colorization I had before to apply to the new sprites properly.

At the moment I am basically just shoving some HSV values at the sprite, and it does technically work, but not properly. I don't seem to have any real control over the saturation or value/brightness at all like I did before, there only seems to be two levels to them, as if they were being set to 0.0 or 1.0 instantly, though the color itself is very dark and obviously not at full value/brightness and saturation either way.

I don't see any real difference between what I am doing and what the setup I had for the SVG images was, so I am at a bit of a loss. Presumably somewhere in the depths of AndEngine there was something else being done to make it all work properly, and I just don't know what it is to work it in now. The relevant code that I am using, more or less, is :

        float[] temphsv = new float[3];
        int colorAfter = 0;

        Sprite tempSprite = new Sprite(x, y, 400, 600, mSprite);
        temphsv[0] = 120;
        temphsv[1] = 1.0f;
        temphsv[2] = 1.0f;
        colorAfter = Color.HSVToColor(temphsv);
        tempSprite.setColor(Color.red(colorAfter), Color.green(colorAfter), Color.blue(colorAfter));

Technically the way that code is right now the image should be just pure bright green, but instead it is instead a rather dark green and still retaining its shading. I imagine this is something trivial since it worked fine with the SVG images, so any tip on what I'm missing would be great.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文