Author Topic: Changing an image  (Read 1172 times)

kolyamatic

  • Newcomer
  • *
  • Posts: 18
    • View Profile
Changing an image
« on: 09. March 2013, 11:05:54 »
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

  • Jr. Member
  • **
  • Posts: 83
  • want to learn c++, if you want to teach me, pm me!
    • View Profile
Re: Changing an image
« Reply #1 on: 05. November 2013, 19:55:21 »
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

  • Newcomer
  • *
  • Posts: 18
    • View Profile
Re: Changing an image
« Reply #2 on: 08. November 2013, 18:54:05 »
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

  • Jr. Member
  • **
  • Posts: 83
  • want to learn c++, if you want to teach me, pm me!
    • View Profile
Re: Changing an image
« Reply #3 on: 09. November 2013, 03:04:00 »
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: 09. November 2013, 08:33:07 »
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: 09. November 2013, 09:14:47 by Cosmo »

GEEK

  • Jr. Member
  • **
  • Posts: 83
  • want to learn c++, if you want to teach me, pm me!
    • View Profile
Re: Changing an image
« Reply #5 on: 10. November 2013, 00:08:34 »
ow, you mean changing the positions of the pixels :p
sorry, thought you meant rgb values of the pixels...

nice code Cosmo (: