在“红色”中添加一定量RGB值来创建日落效果,请帮忙。 (java)
好的,所以我想要一个程序,可以逐行浏览图片,并向红色值 (RGB) 添加一定量以创建日落效果。唯一的问题是,当你获得红色、绿色和蓝色的不同值时,我无法将 50 添加到红色值来获得日落效果。下面的代码只是负责循环各行并更改像素值的部分。
for(int y=0; y < sunsetPic.getHeight(); y++)
{
for(int x = 0; x < sunsetPic.getWidth(); x++)
{
targetPixel = sunsetPic.getPixel(x,y);
pixelColor = targetPixel.getColor();
redValue = pixelColor.getRed();
greenValue = pixelColor.getGreen();
blueValue = pixelColor.getBlue();
pixelColor = new Color(redVlue + 50, greenValue, blueValue);
targetPixel.setColor(pixelColor);
}
}
正如您所看到的,我不能仅将 50 添加到 redValue 来创建日落效果。有人可以帮我想办法让我的日落影响吗?
Ok, so I want a program that goes through a picture line by line, and adds a certain amount to the red value (RGB) to create a sunset affect. The only problem is that, when you get the different values for red, green, and blue, I cannot add, lets say, 50 to the red value to get a sunset affect. The code below is only the part that is responsible for looping through the lines and changing the pixel values.
for(int y=0; y < sunsetPic.getHeight(); y++)
{
for(int x = 0; x < sunsetPic.getWidth(); x++)
{
targetPixel = sunsetPic.getPixel(x,y);
pixelColor = targetPixel.getColor();
redValue = pixelColor.getRed();
greenValue = pixelColor.getGreen();
blueValue = pixelColor.getBlue();
pixelColor = new Color(redVlue + 50, greenValue, blueValue);
targetPixel.setColor(pixelColor);
}
}
As you can see, I cannot just add 50 to the redValue to create a sunset affect. Can someone please help me by making a way I can get my sunset affect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要实现日落效果,您需要做的不仅仅是添加一点红色。您很有可能还需要去除一些绿色和蓝色。这些去除可能是按比例去除,留下一定百分比的原始颜色。最灵活的技术是使用一个或多个颜色矩阵。这样您就可以根据输入颜色的线性组合独立调整每个输出颜色。通常,您包含 A 颜色,这意味着大多数颜色矩阵都是 4x5,第五个元素是添加或减去的常量,无论输入如何。
这里有一个代码示例,根据您对保真度的需求,您可以根据需要多次调整变换矩阵,直到获得您想要的视觉效果。
To achieve a sunset effect, you need to do a bit more than add a bit of red. Odds are good you'll need to remove a bit of green and blue too. Those removals will likely be proportional removals, leaving a percentage of the original color present. The most flexible technique to go about this is to use one or more color matrices. That way you can independently adjust each output color based on a linear combination of the input colors. Generally, you include the A color, which means that most color matrices are 4x5, with the fifth element being a constant added or subtracted regardless of input.
A code example is here, and depending on your need for fidelity, you can tweak the transformation matrix as many times as you like until you get the visual effects you are seeking.
如果可以的话,将图像加载到 Gimp 或 Photoshop 等绘画程序中,并使用它来编辑和预览颜色变化。一旦获得了您想要的外观,就可以使用您获得的 RGB 百分比,这些将是您的运行时更改。
我建议使用乘数而不是加法,并且我建议不要将红色提高到 1.0 以上,而是遵循 Edwin Buck 的将绿色和蓝色相乘的想法。
If you can, load the image into a paint program like Gimp or Photoshop and use that to edit and preview color changes. Once you get the look you want use the percentages of RGB you arrived at and those will be your runtime changes.
I'd suggest using a multiplier instead of an addition and I'd suggest not boosting your Red above 1.0 but follow Edwin Buck's idea of multiplying down Green and Blue.