Author Topic: Changing an image  (Read 3109 times)

kolyamatic

  • Guest
Changing an image
« 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?

GEEK

  • Guest
Re: Changing an image
« Reply #1 on: November 05, 2013, 06:55:21 PM »
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

kolyamatic

  • Guest
Re: Changing an image
« Reply #2 on: November 08, 2013, 05:54:05 PM »
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() ...)

GEEK

  • Guest
Re: Changing an image
« Reply #3 on: November 09, 2013, 02:04:00 AM »
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?

Cosmo

  • Guest
Re: Changing an image
« Reply #4 on: November 09, 2013, 07:33:07 AM »
Hi,

This is what you want.
Code: [Select]
--' 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()
« Last Edit: November 09, 2013, 08:14:47 AM by Cosmo »

GEEK

  • Guest
Re: Changing an image
« Reply #5 on: November 09, 2013, 11:08:34 PM »
ow, you mean changing the positions of the pixels :p
sorry, thought you meant rgb values of the pixels...

nice code Cosmo (: