Home > Software design >  RMagick Draw Image using Array RGB
RMagick Draw Image using Array RGB

Time:10-31

I have an array of RGB values for individual pixels of a digital result that has analyzed an image. The array represents rows of individual pixels, which make up the image. The resulting image shows me what groups of pixels qualify as being "hot spots".

I'm using RMagick in Ruby and I'm wanting to build this result image from the arrays of pixels that I have. I'm not clear as to how I can import that array as the visual pixel colours. An example:

imagepixels = [
        [[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0]],
        [[0,0,0], [0,0,0], [255,0,0], [0,0,0], [0,0,0]],
        [[0,0,0], [0,0,0], [255,0,0], [255,0,0], [0,0,0]],
        [[0,0,0], [255,0,0], [255,0,0], [255,0,0], [0,0,0]],
        [[0,0,0], [255,0,0], [255,0,0], [255,0,0], [0,0,0]],
        [[0,0,0], [255,0,0], [255,0,0], [255,0,0], [0,0,0]],
        [[0,0,0], [0,0,0], [255,0,0], [255,0,0], [0,0,0]],
        [[0,0,0], [0,0,0], [255,0,0], [0,0,0], [0,0,0]],
        [[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0]]
        ]

I can't seem to get any methods to work from RMagick, but I have found this one, which I'm confused over:

.import_pixels(blob, columns, rows, depth, map, format = 'png') ⇒ MiniMagick::Image

Is there an easier way to get these pixels into the Magick object, then write the file? Or how can I get this done, given the array that I already have?

Cheers

CodePudding user response:

It looks like the constitute method will serve your needs.

  • Related