I use rmagick to process each individual pixel of a bitmap. I need to get the color values in depth 8 (256 colors), but unfortunately when I use a pixel. [Color] (for example, pixel. Red), I get them at a depth of 16. This happens even after I use the .quantize (256) image.
Here is the code:
require 'RMagick'
include Magick
image = ImageList.new("image.bmp")
image3 = image.quantize(number_colors = 256)
puts image3.number_colors
image2 = Image.new(image.columns, image.rows)
(0..image.columns).each do |x|
(0..image.rows).each do |y|
pixel = image3.pixel_color(x, y)
print pixel.red
print ", "
print pixel.green
print ", "
print pixel.blue
print "\n"
image2.pixel_color(x, y, pixel)
end
end
How can I get only 0..255 values?
source
share