Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: [QUIZ][SOLUTION] Mexican Blanket (#127
Tim Hunter
6/10/2007 8:55:00 PM
Justin Ethier wrote:
> And to draw a JPEG we get a bit fancier, but its the same basic idea.
> There
> must be a better way to code this, because it takes much too long to run.
Nice solution! Regarding the speed, see my earlier reply to Jesse
Merriman. Instead of drawing a pixel at a time, create an array of Pixel
objects and then use import_pixels or store_pixels to "draw" a row at a
time. For that matter, both of these methods can handle arbitrary
rectangles so you can create as many rows as you want and stow them in
the image all at once. You could build the whole image in memory if
that's what you wanted.
--
RMagick OS X Installer [
http://rubyforge.org/project...
]
RMagick Hints & Tips [
http://rubyforge.org/forum/forum.php?for...
]
RMagick Installation FAQ [
http://rmagick.rubyforge.org/instal...
]
1 Answer
Jesse Merriman
6/11/2007 10:35:00 PM
0
On Sunday 10 June 2007 16:54, Tim Hunter wrote:
> <snip>
> For that matter, both of these methods can handle arbitrary
> rectangles so you can create as many rows as you want and stow them in
> the image all at once. You could build the whole image in memory if
> that's what you wanted.
Though that does give a speed boost, its not much. Here's a mod of the
last version of draw_blanket I posted:
def draw_blanket blanket
pixels = []
blanket.each_row_with_index do |row, y|
row.split(//).each do |color_char|
pixels << Magick::Pixel.from_color(StringToColor[color_char])
end
end
store_pixels 0, 0, blanket.width, blanket.height, pixels
end
For a 800x800 image, on my box, this shaves about 1/20 second off a total
run time of about 7 seconds.
--
Jesse Merriman
jessemerriman@warpmail.net
http://www.jessemer...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: [QUIZ][SOLUTION] Mexican Blanket (#127
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password