1 from pyforms.web.Controls.ControlBase import ControlBase
2 import cv2
3 import base64
4 import numpy as np
5 import StringIO
6 from PIL import Image
9
10 _filename = ''
11
13 return "controls.push(new ControlImage('"+self._name+"','%s'));" % self.help
14
15 - def save(self, data):
17
18 - def load(self, data):
19 if 'value' in data: self.value = data['value']
20
22
23 @property
25 result = { 'image': '', 'filename': self._filename }
26 image = ControlBase.value.fget(self)
27 if isinstance(image, np.ndarray):
28 if len(image.shape)>2: image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
29 image = Image.fromarray(image)
30 buff = StringIO.StringIO()
31 image.save(buff, format="PNG")
32 content = buff.getvalue()
33 buff.close()
34 result['image'] = base64.b64encode(content)
35 return result
36
37
38 @value.setter
49