I’m trying to using TImage::GetImageBuffer(char** buffer, int* size, TImage::EImageFileTypes type = TImage::kPng) from pyroot. It’s just the first parameter giving me problems.
Do I have to use gROOT.ProcessLine(…)?
I’ve tried this but I don’t seem to get the whole image back. It only fills a little bit of the buffer.
Mac OSX 10.4
putting a buffer through a char** is easy (even if fugly):
a = array.array( 'b', *9 )
addr = array.array( 'l', [ a.buffer_info() ] )where ‘addr’ can now be used for a function that takes a char** argument, and fills it with up to 9 chars (or 3 strings of length 2).
However, what TImage::GetImageBuffer() does, is using the char** as an out-argument. That will work, too, like with:
addr = array.array( 'l',  )and after the GetImageBuffer() call, ‘addr’ will contain the address of the TImage buffer.
But then where does it have to go? Pretty much anything you do with a char* in python gets sooner or later copied into a str object. I don’t think that’s what you want?
Here’s some code:
from ROOT import *
from array import array
from ctypes import *
f1=TF1(‘f1’, ‘sin(x)/x’, 0, 10)
for i in s:
This produces a valid png but there’s no content unfortunately. The PNG header is there when I look at the file in vi, but it’s not putting in the actual plot.
I think the canvas is not being passed correctly or something.
Note: the ctypes modules is in Python 2.5 only I think.
yes, ctypes is 2.5 only. Thanks for pointing out the existence of string_at!
With release 5.14.00, I don’t see anything in my file either. However, it works with CVS HEAD (on Linux, anyway). I tried again with an upgraded pyroot in 5.14.00-patches, which still left the .png empty, so the fix didn’t seem to come from anything I did.
What did help, is to add a line ‘c.Update()’ in your script, just after the f1.Draw() call.
Note that the display of the function in the canvas on the screen doesn’t mean that much, because canvases are updated by the displayhook (called by the python interpreter at the end of your script) and by a separate GUI thread (called intermittently). As such, I’d add the ‘c.Update()’ call always, even for CVS HEAD.