1

In my tkinter GUI a video is displayed and the user is able to get a snapshot of the video. Now I am trying to save this snapshot but i can't figure out how to do it. Due to the imagetype of the file I can't save it with the common Image.save()

The Video Loop:

def stream(label):

    for image in video.iter_data():
        global frame_image

        frame_image = ImageTk.PhotoImage(Image.fromarray(image))
        label.config(image=frame_image)
        label.image = frame_image

        time.sleep(0.015)

The Snapshot function:

def snapshot():

    global frame_image

    frame_label.config(image = frame_image)
    frame_label.image = frame_image

I tried several things but nothing seemed to work.

Tried to convert it to cv2 format to use cv2.imwrite:

open_cv_image = numpy.array(frame_image) 

cv2.imwrite("C:\\test.jpg", open_cv_image)

Tried to open it in a new image with PIL.Image.open:

pic = Image.open(frame_image).convert("RGB")    
pic.save("C:\\test.jpg")

Any idea how I could finally solve my problem?

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Relevant [How to save PIL.ImageTk.PhotoImage as jpg](https://stackoverflow.com/a/45442318/7414759) – stovfl Feb 28 '19 at 15:15
  • 2
    I don't really understand how this post is supposed to help me. The Code example doesn't work for me and the links are just explanations of Image and PhotoImage Module. No example how to save a ImageTk.PhotoImage file. – M. Hirschbichler Feb 28 '19 at 22:05
  • *"No example how to save a ImageTk.PhotoImage file."*: The Answer clearly uses `image.image.save(new_file_path)`. *"Code example doesn't work for me"*: [Edit] your Question and show **what** have you tried and **what** does not work for you. – stovfl Feb 28 '19 at 22:17
  • 2
    That post only says "From there you can get the included Image object", but doesn't say how and the docs don't say how either. – Nicolas Abril Sep 23 '19 at 17:31

0 Answers0