From: Christopher B. <Chr...@no...> - 2007-07-02 21:57:04
|
I don't know how to do it with the MPL agg back-end, but I think you mentioned wx, and you can do it there instead. a wxImage can be constructed from a buffer object, then saved as a PNG. You may need to set the rgb and alpha portions separately. See the wxPython wiki and search for "Image". Also: > matrix = [] > buffer = self.get_renderer().tostring_argb() > l, h = self.GetSize() > for ligne in xrange(h): > matrix.append([]) > for colonne in xrange(l): > i = 4*(ligne*h + colonne) > pixel = buffer[i:i+4] > matrix[-1].append(pixel) This is a very slow way to create the numpy array! Option a: first create an empty array: matrix = numpy.empty((l,h,4), numpy.byte) then fill that in. but even better: you can build the array directly from the buffer string: matrix = numpy.fromstring(buffer, dtype=numpy.byte) lotlib-users -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |