Fix for flickering image in OpenCV demos!!!!

This commit is contained in:
PySimpleGUI 2019-10-07 18:08:06 -04:00
parent 7f1584d97e
commit 18ce3337e6
1 changed files with 37 additions and 35 deletions

View File

@ -1443,39 +1443,39 @@ class Image(Element):
# class SuperImageOld(remi.gui.Image):
# def __init__(self, file_path_name=None, **kwargs):
# image = file_path_name
# super(SuperImage, self).__init__(image, **kwargs)
#
# self.imagedata = None
# self.mimetype = None
# self.encoding = None
# if image is None:
# return
# self.load(image)
#
# def load(self, file_path_name):
# if type(file_path_name) is bytes or len(file_path_name) > 200:
# try:
# self.imagedata = base64.b64decode(file_path_name, validate=True)
# except binascii.Error:
# self.imagedata = file_path_name
# else:
# self.mimetype, self.encoding = mimetypes.guess_type(file_path_name)
# with open(file_path_name, 'rb') as f:
# self.imagedata = f.read()
# self.refresh()
#
# def refresh(self):
# i = int(time.time() * 1e6)
# self.attributes['src'] = "/%s/get_image_data?update_index=%d" % (id(self), i)
#
# def get_image_data(self, update_index):
# headers = {'Content-type': self.mimetype if self.mimetype else 'application/octet-stream'}
# return [self.imagedata, headers]
class SuperImage(remi.gui.Image): class SuperImage(remi.gui.Image):
def __init__(self, file_path_name=None, **kwargs):
image = file_path_name
super(SuperImage, self).__init__(image, **kwargs)
self.imagedata = None
self.mimetype = None
self.encoding = None
if image is None:
return
self.load(image)
def load(self, file_path_name):
if type(file_path_name) is bytes or len(file_path_name) > 200:
try:
self.imagedata = base64.b64decode(file_path_name, validate=True)
except binascii.Error:
self.imagedata = file_path_name
else:
self.mimetype, self.encoding = mimetypes.guess_type(file_path_name)
with open(file_path_name, 'rb') as f:
self.imagedata = f.read()
self.refresh()
def refresh(self):
i = int(time.time() * 1e6)
self.attributes['src'] = "/%s/get_image_data?update_index=%d" % (id(self), i)
def get_image_data(self, update_index):
headers = {'Content-type': self.mimetype if self.mimetype else 'application/octet-stream'}
return [self.imagedata, headers]
class SuperImagenew(remi.gui.Image):
def __init__(self, file_path_name=None, **kwargs): def __init__(self, file_path_name=None, **kwargs):
""" """
This new app_instance variable is causing lots of problems. I do not know the value of the App This new app_instance variable is causing lots of problems. I do not know the value of the App
@ -1496,7 +1496,9 @@ class SuperImagenew(remi.gui.Image):
def load(self, file_path_name): def load(self, file_path_name):
if type(file_path_name) is bytes or len(file_path_name) > 200: if type(file_path_name) is bytes or len(file_path_name) > 200:
self.imagedata = base64.b64decode(file_path_name) # print("image data")
self.mimetype = 'image/png'
self.imagedata = file_path_name #base64.b64decode(file_path_name)
else: else:
self.mimetype, self.encoding = mimetypes.guess_type(file_path_name) self.mimetype, self.encoding = mimetypes.guess_type(file_path_name)
with open(file_path_name, 'rb') as f: with open(file_path_name, 'rb') as f:
@ -1504,6 +1506,7 @@ class SuperImagenew(remi.gui.Image):
self.refresh() self.refresh()
def refresh(self): def refresh(self):
# print("refresh")
i = int(time.time() * 1e6) i = int(time.time() * 1e6)
# self.app_instance.execute_javascript(""" # self.app_instance.execute_javascript("""
if Window.App is not None: if Window.App is not None:
@ -1521,11 +1524,10 @@ class SuperImagenew(remi.gui.Image):
""" % {'id': id(self), 'frame_index':i}) """ % {'id': id(self), 'frame_index':i})
def get_image_data(self, update_index): def get_image_data(self, update_index):
# print("get image data")
headers = {'Content-type': self.mimetype if self.mimetype else 'application/octet-stream'} headers = {'Content-type': self.mimetype if self.mimetype else 'application/octet-stream'}
return [self.imagedata, headers] return [self.imagedata, headers]
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
# Graph # # Graph #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #