# Encoding: UTF-8
ever again :) (UTF-8 is the default now.)Gosu::Image
, call to_blob
on it (be sure to cache the result) and parse the binary data. Something like:class Gosu::Image
def [](x, y) # Returns a binary string with r/g/b/a as the characters
@blob ||= self.to_blob
if x < 0 or x >= width or y < 0 or y >= height
"\0\0\0\0" # return transparent pixels by default; you could also return nil
else
@blob[(y * width + x) * 4, 4]
end
end
end
...
some_image[x, y] # to read a pixel
||=
operator does the caching here.record
-ed ones), unlike gl_tex_info
etc. which can fail for very large images.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill