views:

200

answers:

2

I tried using Win32's GetPixel() with Ruby and it is really slow even on a Quad Core Intel machine. I think for example, if I get a really small region such as 100 x 10 pixels = 1000 pixels and it can take 30 seconds to complete. Is there a better way such as by getting a region all at once?

+1  A: 

I think the function you want is BitBlt.

Auraseer
+1  A: 

I don't know much about Ruby, but isn't it interpreted? If it is and you are invoke a Win32 API call through presumable one of Rubys librarys and on top of that calling GetPixel, well then yes, it would be slow.

If you have access to the Win32 api's through Ruby then you should look into BitBlt. Bit-Block-Transfer which will return a buffer of values rather than individual values. This will be many times faster.

Of course, now you have to deal with Device Context's, Bitmap structures and raw memory, which are perhaps lower level constructs than Ruby provides for.

http://winprog.org/tutorial/bitmaps.html