Hello,
I'm currently trying to build an image file (jpg/gif) from a stream of
pixel colour values, but it's taking a long time to build the image
pixel by pixel.
We're trying to dynamically "screenshot" a Flash movie to create a
static JPG. The flash movie plays to the appropriate point then
effectively does a "capture" of each pixel's colour, posting the
information directly to a ruby socket server.
From there a new RMagick::Image is created and each pixel is painted
individually on to that image (see RippedImage#draw below). While this
works, it's very slow when we get up to the sort of image resolution
we're looking at, taking about 40 seconds for a 512x384 image.
Does anyone have any suggestions as to how to increase this generation
speed? I've tried hunting through the RMagick docs for some way to
provide an array of pixel data or something similar, but nothing's
jumped out at me. Test code below.
Thanks in advance,
Tim.
require 'RMagick'
class RippedImage
def initialize (jobid, width, height)
@jobid = jobid.to_s;
@width = width.to_i;
@height = height.to_i;
@canvas = Magick::Image.new(@width, @height)
end
def draw (x, y, c)
Magick::Draw.new.fill('#'+c).point(x,y).draw(@canvas)
end
def finalize (type="jpg")
@canvas.write("#{@jobid}.#{type}")
end
end
x = 512
y = 384
colours = ["ff0000", "00ff00", "0000ff"]
img = RippedImage.new(1, x, y)
for x in 0..x
for y in 0..y
img.draw(x, y, colours[rand(colours.length)])
end
end
img.finalize
···
--
-------------------------------------------------------
TB: http://tim.bla.ir/ Tech: http://tech.badpen.com/
-------------------------------------------------------
RAWNET LTD - independent digital media agency
"We are big, we are funny and we are clever!"
http://www.rawnet.com/
-------------------------------------------------------
This message may contain information which is legally
privileged and/or confidential. If you are not the
intended recipient, you are hereby notified that any
unauthorised disclosure, copying, distribution or use
of this information is strictly prohibited. Such
notification notwithstanding, any comments, opinions,
information or conclusions expressed in this message
are those of the originator, not of rawnet limited,
unless otherwise explicitly and independently indicated
by an authorised representative of rawnet limited.
-------------------------------------------------------