From: Timothy Hunter Date: 2005-12-31T20:09:28+09:00 Subject: Re: Making screenshots with Ruby guest@guest.com wrote: > Oh and forgot to add - I'm using them later with RMagick, so I'd want > them loaded in memory in a way that RMagick can understand them, but if > it has to it can be saved to file too :) > There are a couple of ways to construct an RMagick image without reading an image file. If the screenshot data is in a Ruby string in one of the formats that ImageMagick/GraphicsMagick understands (JPEG, GIF, BMP, or one of the 80+ others) then you can use Image.from_blob[1]. If the screenshot data is in a Ruby string (or an instance of any class with a to_str method, such as NArray) and is simply "raw" pixel data in scanline order (left-to-right, top-to-bottom) you use the Image.import_pixels method. It's blindingly fast. (I'd give you a URL to the doc, but the online doc is sufficiently out-of-date that it doesn't describe how import_pixels exploits to_str. You can get the details from your local copy of the RMagick doc.) [1] http://www.simplesystems.org/RMagick/doc/image1.html#from_blob