JAVA:使用 ColorModel 用另一种颜色替换一种颜色 [英] JAVA: Substitute one color with another using ColorModel

查看:36
本文介绍了JAVA:使用 ColorModel 用另一种颜色替换一种颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在图像上用白色替换一种颜色.我已经阅读了 ColorModel 和 RGBImageFilter.substituteColorModel,但我不太了解.

I need to substitute one color with white on an image. I've read about ColorModel and RGBImageFilter.substituteColorModel, but I don't understand very well.

我要替换的颜色是:回复: 113克:75乙:96

The color I want to substitute is: R: 113 G: 75 B: 96

当然,白色是 255,255,255.

And of course, white is 255,255,255.

如果你能给出一个直接的解决方案会很好,但如果不能,一些关于如何去做的解释也会很好.我不只是想要解决方案,我想要了解方法和原因.

If you can give a direct solution will be great, but if not, a bit of explanation on how to do it also will be great. I don't want just the solution, I want to understand the hows and whys.

非常感谢你.

推荐答案

在我的公司,我们必须经常在嵌入式显示器上进行这种切换.我们使用索引位图来完成您所谈论的内容.基本思想是切换给定索引的调色板以获得不同的外观和感觉.

At my company we have to do this sort of switching frequently on embedded displays. We use indexed bitmaps to accomplish what you are talking about. The basic idea is to switch out the palette for a given index to get different looks and feels.

索引位图的想法是您可以在调色板中使用 256 种颜色.您可以为调色板中的每个插槽分配所需的任何 RGB 值.图像本身只是调色板中的索引列表(每个像素一个字节).这在 CPU 和存储受限平台上真的很酷(您无法处理解压缩图像,也无法为全色位图腾出空间).您可以制作备用调色板(绿色、黄色、红色等).您只需切换调色板,图形看起来就完全不同了.我们使用它在小部件上制作非常精细的渐变,这些小部件可以切换颜色而无需携带按钮的每个状态.

The idea with an indexed bitmap is that you have say 256 colors at your disposal in the pallete. You can assign any RGB values that you want to each slot in the palette. The image itself is just a list of indexes into the palette(single byte per pixel). This is really cool on CPU and storage constrained platform(where you can't deal with decompressing images and you can't spare the space for full color bitmaps). You can make alternate palettes (greens, yellows, reds, etc). You just switch out the palette and the graphics look completely different. We use this to make really fine gradients on widgets that can switch color without having to carry around each state of a button.

要解决索引位图的具体问题,您只需切换调色板并确保在一个调色板中的索引是 (113,75,96),而在第二个调色板中保持相同的索引 (255,255,255).

To solve your specific problem with indexed bitmaps, you would just switch palettes and make sure that in one palette the index was (113,75,96) and in the second palette that same index held (255,255,255).

IndexColorModel 是从 AWT 开始的好地方.

IndexColorModel is a good place to start in AWT.

祝你好运!

这篇关于JAVA:使用 ColorModel 用另一种颜色替换一种颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆