java的colormodel,JAVA:替换一种颜色与另一个使用的ColorModel

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.

The color I want to substitute is:

R: 113

G: 75

B: 96

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.

Thank u so much.

解决方案

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.

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.

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 is a good place to start in AWT.

Good luck!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值