RetroBASIC
Retrogamecoding(.org) => EGSL => Topic started by: kolyamatic on March 09, 2013, 10:05:54 AM
-
Here is another of my many questions:
How would I alter the R/G/B value of a certain pixel of a certain image?
I do have a way to do so but there may be other ideas or even commands one could use.
Hence; how to do so?
-
just use:
screenred (x,y)
screengreen (x,y)
screenblue (x,y)
Example
screen (640,480,"GetPixel Test")
color (123,50,70)
dot (200,200)
blue=screenblue (200,200)
--' blue has the value of 70
-
Well, this changes the RGB values of the pixels onscreen.
But I would like to change an image's pixels' values. Until now I could only put it on the screen, change the dots all seperately and then save the image back as it is on the screen. (via grabimage(), saveimage() ...)
-
well, there is no way of changing them all at the same time, just write a function for that, but you can change the bits:
openwindow(x,y,16,str)
you can say the image must be, 8 to 32 bits.
can you show me what you want to do in code or in some image example? maybe i can help you further?
-
Hi,
This is what you want.
--' By Cosmo Alias Peter Wirbelauer.
screen(640,480,0,"ImagePixel")
setframetimer(24)
backcolor(75,100,200)
function RGB(r,g,b)
g = g * 256
b = b * 65536
return r+g+b
end
local wAmp=6;wFreq=0.3;x=0;m=0;dx=0;cx=0;col=0;r=0;g=0;b=0;kn=0
kn= loadimage("egsl-icon.png")
repeat
key=getkey()
cls()
x = x - .5
m = x
for cx=0, imageheight(kn)-1 do
m = m + wFreq
for dx=0, imagewidth(kn)-1 do
r= imagered (dx,cx,kn)
g= imagegreen(dx,cx,kn)
b= imageblue (dx,cx,kn)
color(r,g,b)
if RGB(r,g,b) > 0 then
fillcircle(150+dx*2+sin(m)*wAmp+1,100+cx*2,2)
end
end
end
color(255,255,255)
sync()
until key == 27
CloseWindow()
-
ow, you mean changing the positions of the pixels :p
sorry, thought you meant rgb values of the pixels...
nice code Cosmo (: