开发者

How to replace all pixels of some color in a bitmap in Rebol?

Let's say I have a picture, I want to create some variations by changing a color. How to do this ?

I don't want to apply color filter to a picture, I want to c开发者_运维知识库hange pixels color pixel by pixel by testing a color pixel if it is let's say red, i want to turn it to blue.


In Rebol images are also series, so you can use most of the series functions to change/find rgb colors etc.

i: load %test.png
type? i
image!
first i
255.255.255.0 (the last value is alpha)
change i 255.0.0.0 ;change the first rgba value to red
view layout [image i] ;you can see the upper-left pixel is now red

you can dump all rgba values in an image:

forall i [print first i]

you can also change a continues part:

change/dup head i blue 100 ;change first 100 pixels to blue

you can also work on i/rgb and i/alpha, these are binary values (bytes) and you can use copy to get a part of an image:

j: copy/part at i 100x100 50x50 ;copy from 100x100 to 150x150 to a new image.


Use some of the image processing capabilities as documented here: http://www.rebol.com/docs/view-guide.html

Demo program showing some of them in action here: http://www.rebol.com/view/demos/gel.r

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜