From: Jeff Rose Date: 2005-07-20T17:31:31+09:00 Subject: Re: RMagick Help -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I happen to be doing something similar right now. Here's some code that should show one way to do it... This prints out the 8-bit pixel values for any image(s) passed on the command-line. (Just chopping off the low order byte...) Example: ruby foo.rb images/*.png - -------------------------------- require 'RMagick' imageList = Magick::ImageList.new(*ARGV) imageList.each do |image| puts "Bits Per Pixel: #{image.depth}" view = image.view(0, 0, image.columns, image.rows) 0.upto(view.width) do |x| 0.upto(view.height) do |y| red = view[x][y].red >> 8 green = view[x][y].green >> 8 blue = view[x][y].blue >> 8 puts "(#{red}, #{green}, #{blue})" end end end - ------------------------------- Peace, Jeff Michael Leonard wrote: > Hello, > > I finally got RMagick working on my OS X machine and I'm trying to use > it to accomplish some things that I was previously doing with > ImageMagick through the %x mechanism. Specifically, I want to read in an > image and spit out a list of individual rgb values. This seems easy enough: > > @sourceimage=Image::read(@filename).first > @sourceimage.get_pixels(0, 0, @sourceimage.columns, @sourceimage.rows) > > What I really want, though, is 8-bit color values (0-255) rather than > the 16-bit values (0-65535) that get spit out. Does anyone know how to > go about this? I feel like it must be possible, but I've been back and > forth through the documentation and can't figure it out. Any help would > be greatly appreciated. > > Thanks, > > miek > > > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFC3gvGABKrmewgEfIRAsOsAJ9054dU471Livt6+j8CYuUYmYDLjgCgkOd+ HFmWc0PlKNht3GqYhzXC2BY= =ScTw -----END PGP SIGNATURE-----