Repository: pyqtgraph/pyqtgraph

Issue:
export image bug related to type casting
Hi there,

I've got a Qt5-only Python distro installed (WinPython 3.5 Qt5) which includes pyqtgraph 0.10.0. Exporting images from PlotWidgets and ImageViews doesn't work anymore and gives this exception:

`Traceback (most recent call last):
  File "C:\WinPython35_Qt5\python-3.5.3.amd64\lib\site-packages\pyqtgraph\exporters\Exporter.py", line 77, in fileSaveFinished
    self.export(fileName=fileName, **self.fileDialog.opts)
  File "C:\WinPython35_Qt5\python-3.5.3.amd64\lib\site-packages\pyqtgraph\exporters\ImageExporter.py", line 70, in export
    bg = np.empty((self.params['width'], self.params['height'], 4), dtype=np.ubyte)
TypeError: 'float' object cannot be interpreted as an integer
QWaitCondition: Destroyed while threads are still waiting`

Didn't happen with WinPython 3.5 Qt4 (pyqtgraph 0.9.10 I think). Am I the only one experiencing this?

Update: simple fix: in ImageExporter.py, line 70:
`bg = np.empty((int(self.params['width']), int(self.params['height']), 4), dtype=np.ubyte)`


Discussion:
No, I got the same thing in debian testing, and I fixed it exactly same

BTW the error can be reproduced not always, but most of time if scaling the image before saving it. Sometimes when output dimension is not changed it saves the picture, but if it is changed most of time it does not save it.
Hehe, I see. I made a PR: #457
thank you!! I fixed as your guide, but for python 2.7 although it has announced this error, it has still exported image. 
The fix here is a bit a hack, the real problem is that parameter tree `param` have declared variables `height` an `width` to be integers, but are cast to float with any change in those parameters.
@cuongtv89ks is right. This bug is related to the latest numpy throwing an exception when using floats in np.empty(). Older versions just give a warning:
`VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future`
I wonder if there are more lines in the code like that...


Resolving patch:
diff --git a/pyqtgraph/exporters/ImageExporter.py b/pyqtgraph/exporters/ImageExporter.py
--- a/pyqtgraph/exporters/ImageExporter.py
+++ b/pyqtgraph/exporters/ImageExporter.py
@@ -23,8 +23,8 @@ def __init__(self, item):
             bg.setAlpha(0)
             
         self.params = Parameter(name='params', type='group', children=[
-            {'name': 'width', 'type': 'int', 'value': tr.width(), 'limits': (0, None)},
-            {'name': 'height', 'type': 'int', 'value': tr.height(), 'limits': (0, None)},
+            {'name': 'width', 'type': 'int', 'value': int(tr.width()), 'limits': (0, None)},
+            {'name': 'height', 'type': 'int', 'value': int(tr.height()), 'limits': (0, None)},
             {'name': 'antialias', 'type': 'bool', 'value': True},
             {'name': 'background', 'type': 'color', 'value': bg},
         ])
@@ -34,12 +34,12 @@ def __init__(self, item):
     def widthChanged(self):
         sr = self.getSourceRect()
         ar = float(sr.height()) / sr.width()
-        self.params.param('height').setValue(self.params['width'] * ar, blockSignal=self.heightChanged)
+        self.params.param('height').setValue(int(self.params['width'] * ar), blockSignal=self.heightChanged)
         
     def heightChanged(self):
         sr = self.getSourceRect()
         ar = float(sr.width()) / sr.height()
-        self.params.param('width').setValue(self.params['height'] * ar, blockSignal=self.widthChanged)
+        self.params.param('width').setValue(int(self.params['height'] * ar), blockSignal=self.widthChanged)
         
     def parameters(self):
         return self.params


Test patch: