From: Tim Hunter Date: 2009-03-23T08:01:16+09:00 Subject: Re: convert PNG to hex jeljer te Wies wrote: > Eric Jacoboni wrote: >> jeljer te Wies writes: >> >> >>> Here is some sample code i made but doesn't work: >>> >>> f = File.new("PNG.png") >>> image = f.readlines >>> >>> puts image.to_hex >> >> Without knowing exactly what you want to do... >> >> 1) f.readlines gives an *Array* of strings >> 2) to_hex doesn't exist in Ruby. You probably want sprintf "%X" > > well to explain why I want to do this! :P .. > here is my ehm... job discription: > > The pixels in the above image are numbered 0..99 for the first row, > 100..199 for the second row etc. White pixels represent ascii codes. The > ascii code for a particular white pixel is equal to the offset from the > last white pixel. For example, the first white pixel at location 65 > would represent ascii code 65 ('A'), the next at location 131 would > represent ascii code (131 - 65) = 66 ('B') and so on > > The text contained in the image is the answer encoded in Morse, where "a > test" would be encoded as ".- / - . ... -" > > This is what I have to do.. that's why I need some kind of hex codes in > a long string or array so I can see what pixels are white and which one > are black > > Thanxs for the fast reply! With RMagick you can get the pixel values with #get_pixels [http://studio.imagemagick.org/RMagick/doc/image2.html#get_pixels] or #view [http://studio.imagemagick.org/RMagick/doc/image3.html#view]. -- RMagick: http://rmagick.rubyforge.org/