Post Reply 
Python: How do I save a graphic?
01-04-2023, 11:50 PM
Post: #8
RE: Python: How do I save a graphic?
Guenter,

I figured out a way to save graphic images to files from within Python. What works for me is to embed the function calls inside a call to the HOME EVAL() function inside the Python "hpprime.eval()" call. The EVAL() function is placed inside escaped single quotes like this: hpprime.eval('\'EVAL(<inserted function>)\'').

The following Python program saves a GROB image created in G1 to the file "pic.png".

Code:

import hpprime

def screen_cap():
  hpprime.eval('\'EVAL(DIMGROB_P(G1,320,240))\'') 
  hpprime.eval('\'EVAL(RECT())\'')
  hpprime.eval('\'EVAL(RECT_P(G1,40,40,280,200,#000000,#00FF00))\'') 
  b="\"pic.png\""
  t='\'EVAL(AFiles('+b+'):=G1)\''
  print(t)
  m=hpprime.eval(t)
  print(m)
screen_cap()

If the EVAL() function isn't used, no file is saved.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Python: How do I save a graphic? - leibniz - 01-04-2023 11:50 PM



User(s) browsing this thread: 1 Guest(s)