prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN 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)`
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pyqtgraph/exporters/ImageExporter.py`
  Content:
  ```
  1 from .Exporter import Exporter
  2 from ..parametertree import Parameter
  3 from ..Qt import QtGui, QtCore, QtSvg, USE_PYSIDE
  4 from .. import functions as fn
  5 import numpy as np
  6 
  7 __all__ = ['ImageExporter']
  8 
  9 class ImageExporter(Exporter):
  10     Name = "Image File (PNG, TIF, JPG, ...)"
  11     allowCopy = True
  12     
  13     def __init__(self, item):
  14         Exporter.__init__(self, item)
  15         tr = self.getTargetRect()
  16         if isinstance(item, QtGui.QGraphicsItem):
  17             scene = item.scene()
  18         else:
  19             scene = item
  20         bgbrush = scene.views()[0].backgroundBrush()
  21         bg = bgbrush.color()
  22         if bgbrush.style() == QtCore.Qt.NoBrush:
  23             bg.setAlpha(0)
  24             
  25         self.params = Parameter(name='params', type='group', children=[
  26             {'name': 'width', 'type': 'int', 'value': tr.width(), 'limits': (0, None)},
  27             {'name': 'height', 'type': 'int', 'value': tr.height(), 'limits': (0, None)},
  28             {'name': 'antialias', 'type': 'bool', 'value': True},
  29             {'name': 'background', 'type': 'color', 'value': bg},
  30         ])
  31         self.params.param('width').sigValueChanged.connect(self.widthChanged)
  32         self.params.param('height').sigValueChanged.connect(self.heightChanged)
  33         
  34     def widthChanged(self):
  35         sr = self.getSourceRect()
  36         ar = float(sr.height()) / sr.width()
  37         self.params.param('height').setValue(self.params['width'] * ar, blockSignal=self.heightChanged)
  38         
  39     def heightChanged(self):
  40         sr = self.getSourceRect()
  41         ar = float(sr.width()) / sr.height()
  42         self.params.param('width').setValue(self.params['height'] * ar, blockSignal=self.widthChanged)
  43         
  44     def parameters(self):
  45         return self.params
  46     
  47     def export(self, fileName=None, toBytes=False, copy=False):
  48         if fileName is None and not toBytes and not copy:
  49             if USE_PYSIDE:
  50                 filter = ["*."+str(f) for f in QtGui.QImageWriter.supportedImageFormats()]
  51             else:
  52                 filter = ["*."+bytes(f).decode('utf-8') for f in QtGui.QImageWriter.supportedImageFormats()]
  53             preferred = ['*.png', '*.tif', '*.jpg']
  54             for p in preferred[::-1]:
  55                 if p in filter:
  56                     filter.remove(p)
  57                     filter.insert(0, p)
  58             self.fileSaveDialog(filter=filter)
  59             return
  60             
  61         targetRect = QtCore.QRect(0, 0, self.params['width'], self.params['height'])
  62         sourceRect = self.getSourceRect()
  63         
  64         
  65         #self.png = QtGui.QImage(targetRect.size(), QtGui.QImage.Format_ARGB32)
  66         #self.png.fill(pyqtgraph.mkColor(self.params['background']))
  67         w, h = self.params['width'], self.params['height']
  68         if w == 0 or h == 0:
  69             raise Exception("Cannot export image with size=0 (requested export size is %dx%d)" % (w,h))
  70         bg = np.empty((self.params['width'], self.params['height'], 4), dtype=np.ubyte)
  71         color = self.params['background']
  72         bg[:,:,0] = color.blue()
  73         bg[:,:,1] = color.green()
  74         bg[:,:,2] = color.red()
  75         bg[:,:,3] = color.alpha()
  76         self.png = fn.makeQImage(bg, alpha=True)
  77         
  78         ## set resolution of image:
  79         origTargetRect = self.getTargetRect()
  80         resolutionScale = targetRect.width() / origTargetRect.width()
  81         #self.png.setDotsPerMeterX(self.png.dotsPerMeterX() * resolutionScale)
  82         #self.png.setDotsPerMeterY(self.png.dotsPerMeterY() * resolutionScale)
  83         
  84         painter = QtGui.QPainter(self.png)
  85         #dtr = painter.deviceTransform()
  86         try:
  87             self.setExportMode(True, {'antialias': self.params['antialias'], 'background': self.params['background'], 'painter': painter, 'resolutionScale': resolutionScale})
  88             painter.setRenderHint(QtGui.QPainter.Antialiasing, self.params['antialias'])
  89             self.getScene().render(painter, QtCore.QRectF(targetRect), QtCore.QRectF(sourceRect))
  90         finally:
  91             self.setExportMode(False)
  92         painter.end()
  93         
  94         if copy:
  95             QtGui.QApplication.clipboard().setImage(self.png)
  96         elif toBytes:
  97             return self.png
  98         else:
  99             self.png.save(fileName)
  100         
  101 ImageExporter.register()        
  102         
  103
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: 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 @@
               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 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
  
verification_info: {"golden_diff": "diff --git a/pyqtgraph/exporters/ImageExporter.py b/pyqtgraph/exporters/ImageExporter.py\n--- a/pyqtgraph/exporters/ImageExporter.py\n+++ b/pyqtgraph/exporters/ImageExporter.py\n@@ -23,8 +23,8 @@\n             bg.setAlpha(0)\n             \n         self.params = Parameter(name='params', type='group', children=[\n-            {'name': 'width', 'type': 'int', 'value': tr.width(), 'limits': (0, None)},\n-            {'name': 'height', 'type': 'int', 'value': tr.height(), 'limits': (0, None)},\n+            {'name': 'width', 'type': 'int', 'value': int(tr.width()), 'limits': (0, None)},\n+            {'name': 'height', 'type': 'int', 'value': int(tr.height()), 'limits': (0, None)},\n             {'name': 'antialias', 'type': 'bool', 'value': True},\n             {'name': 'background', 'type': 'color', 'value': bg},\n         ])\n@@ -34,12 +34,12 @@\n     def widthChanged(self):\n         sr = self.getSourceRect()\n         ar = float(sr.height()) / sr.width()\n-        self.params.param('height').setValue(self.params['width'] * ar, blockSignal=self.heightChanged)\n+        self.params.param('height').setValue(int(self.params['width'] * ar), blockSignal=self.heightChanged)\n         \n     def heightChanged(self):\n         sr = self.getSourceRect()\n         ar = float(sr.width()) / sr.height()\n-        self.params.param('width').setValue(self.params['height'] * ar, blockSignal=self.widthChanged)\n+        self.params.param('width').setValue(int(self.params['height'] * ar), blockSignal=self.widthChanged)\n         \n     def parameters(self):\n         return self.params\n", "issue": "export image bug related to type casting\nHi there,\r\n\r\nI'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:\r\n\r\n`Traceback (most recent call last):\r\n  File \"C:\\WinPython35_Qt5\\python-3.5.3.amd64\\lib\\site-packages\\pyqtgraph\\exporters\\Exporter.py\", line 77, in fileSaveFinished\r\n    self.export(fileName=fileName, **self.fileDialog.opts)\r\n  File \"C:\\WinPython35_Qt5\\python-3.5.3.amd64\\lib\\site-packages\\pyqtgraph\\exporters\\ImageExporter.py\", line 70, in export\r\n    bg = np.empty((self.params['width'], self.params['height'], 4), dtype=np.ubyte)\r\nTypeError: 'float' object cannot be interpreted as an integer\r\nQWaitCondition: Destroyed while threads are still waiting`\r\n\r\nDidn't happen with WinPython 3.5 Qt4 (pyqtgraph 0.9.10 I think). Am I the only one experiencing this?\r\n\r\nUpdate: simple fix: in ImageExporter.py, line 70:\r\n`bg = np.empty((int(self.params['width']), int(self.params['height']), 4), dtype=np.ubyte)`\n", "before_files": [{"content": "from .Exporter import Exporter\nfrom ..parametertree import Parameter\nfrom ..Qt import QtGui, QtCore, QtSvg, USE_PYSIDE\nfrom .. import functions as fn\nimport numpy as np\n\n__all__ = ['ImageExporter']\n\nclass ImageExporter(Exporter):\n    Name = \"Image File (PNG, TIF, JPG, ...)\"\n    allowCopy = True\n    \n    def __init__(self, item):\n        Exporter.__init__(self, item)\n        tr = self.getTargetRect()\n        if isinstance(item, QtGui.QGraphicsItem):\n            scene = item.scene()\n        else:\n            scene = item\n        bgbrush = scene.views()[0].backgroundBrush()\n        bg = bgbrush.color()\n        if bgbrush.style() == QtCore.Qt.NoBrush:\n            bg.setAlpha(0)\n            \n        self.params = Parameter(name='params', type='group', children=[\n            {'name': 'width', 'type': 'int', 'value': tr.width(), 'limits': (0, None)},\n            {'name': 'height', 'type': 'int', 'value': tr.height(), 'limits': (0, None)},\n            {'name': 'antialias', 'type': 'bool', 'value': True},\n            {'name': 'background', 'type': 'color', 'value': bg},\n        ])\n        self.params.param('width').sigValueChanged.connect(self.widthChanged)\n        self.params.param('height').sigValueChanged.connect(self.heightChanged)\n        \n    def widthChanged(self):\n        sr = self.getSourceRect()\n        ar = float(sr.height()) / sr.width()\n        self.params.param('height').setValue(self.params['width'] * ar, blockSignal=self.heightChanged)\n        \n    def heightChanged(self):\n        sr = self.getSourceRect()\n        ar = float(sr.width()) / sr.height()\n        self.params.param('width').setValue(self.params['height'] * ar, blockSignal=self.widthChanged)\n        \n    def parameters(self):\n        return self.params\n    \n    def export(self, fileName=None, toBytes=False, copy=False):\n        if fileName is None and not toBytes and not copy:\n            if USE_PYSIDE:\n                filter = [\"*.\"+str(f) for f in QtGui.QImageWriter.supportedImageFormats()]\n            else:\n                filter = [\"*.\"+bytes(f).decode('utf-8') for f in QtGui.QImageWriter.supportedImageFormats()]\n            preferred = ['*.png', '*.tif', '*.jpg']\n            for p in preferred[::-1]:\n                if p in filter:\n                    filter.remove(p)\n                    filter.insert(0, p)\n            self.fileSaveDialog(filter=filter)\n            return\n            \n        targetRect = QtCore.QRect(0, 0, self.params['width'], self.params['height'])\n        sourceRect = self.getSourceRect()\n        \n        \n        #self.png = QtGui.QImage(targetRect.size(), QtGui.QImage.Format_ARGB32)\n        #self.png.fill(pyqtgraph.mkColor(self.params['background']))\n        w, h = self.params['width'], self.params['height']\n        if w == 0 or h == 0:\n            raise Exception(\"Cannot export image with size=0 (requested export size is %dx%d)\" % (w,h))\n        bg = np.empty((self.params['width'], self.params['height'], 4), dtype=np.ubyte)\n        color = self.params['background']\n        bg[:,:,0] = color.blue()\n        bg[:,:,1] = color.green()\n        bg[:,:,2] = color.red()\n        bg[:,:,3] = color.alpha()\n        self.png = fn.makeQImage(bg, alpha=True)\n        \n        ## set resolution of image:\n        origTargetRect = self.getTargetRect()\n        resolutionScale = targetRect.width() / origTargetRect.width()\n        #self.png.setDotsPerMeterX(self.png.dotsPerMeterX() * resolutionScale)\n        #self.png.setDotsPerMeterY(self.png.dotsPerMeterY() * resolutionScale)\n        \n        painter = QtGui.QPainter(self.png)\n        #dtr = painter.deviceTransform()\n        try:\n            self.setExportMode(True, {'antialias': self.params['antialias'], 'background': self.params['background'], 'painter': painter, 'resolutionScale': resolutionScale})\n            painter.setRenderHint(QtGui.QPainter.Antialiasing, self.params['antialias'])\n            self.getScene().render(painter, QtCore.QRectF(targetRect), QtCore.QRectF(sourceRect))\n        finally:\n            self.setExportMode(False)\n        painter.end()\n        \n        if copy:\n            QtGui.QApplication.clipboard().setImage(self.png)\n        elif toBytes:\n            return self.png\n        else:\n            self.png.save(fileName)\n        \nImageExporter.register()        \n        \n", "path": "pyqtgraph/exporters/ImageExporter.py"}], "after_files": [{"content": "from .Exporter import Exporter\nfrom ..parametertree import Parameter\nfrom ..Qt import QtGui, QtCore, QtSvg, USE_PYSIDE\nfrom .. import functions as fn\nimport numpy as np\n\n__all__ = ['ImageExporter']\n\nclass ImageExporter(Exporter):\n    Name = \"Image File (PNG, TIF, JPG, ...)\"\n    allowCopy = True\n    \n    def __init__(self, item):\n        Exporter.__init__(self, item)\n        tr = self.getTargetRect()\n        if isinstance(item, QtGui.QGraphicsItem):\n            scene = item.scene()\n        else:\n            scene = item\n        bgbrush = scene.views()[0].backgroundBrush()\n        bg = bgbrush.color()\n        if bgbrush.style() == QtCore.Qt.NoBrush:\n            bg.setAlpha(0)\n            \n        self.params = Parameter(name='params', type='group', children=[\n            {'name': 'width', 'type': 'int', 'value': int(tr.width()), 'limits': (0, None)},\n            {'name': 'height', 'type': 'int', 'value': int(tr.height()), 'limits': (0, None)},\n            {'name': 'antialias', 'type': 'bool', 'value': True},\n            {'name': 'background', 'type': 'color', 'value': bg},\n        ])\n        self.params.param('width').sigValueChanged.connect(self.widthChanged)\n        self.params.param('height').sigValueChanged.connect(self.heightChanged)\n        \n    def widthChanged(self):\n        sr = self.getSourceRect()\n        ar = float(sr.height()) / sr.width()\n        self.params.param('height').setValue(int(self.params['width'] * ar), blockSignal=self.heightChanged)\n        \n    def heightChanged(self):\n        sr = self.getSourceRect()\n        ar = float(sr.width()) / sr.height()\n        self.params.param('width').setValue(int(self.params['height'] * ar), blockSignal=self.widthChanged)\n        \n    def parameters(self):\n        return self.params\n    \n    def export(self, fileName=None, toBytes=False, copy=False):\n        if fileName is None and not toBytes and not copy:\n            if USE_PYSIDE:\n                filter = [\"*.\"+str(f) for f in QtGui.QImageWriter.supportedImageFormats()]\n            else:\n                filter = [\"*.\"+bytes(f).decode('utf-8') for f in QtGui.QImageWriter.supportedImageFormats()]\n            preferred = ['*.png', '*.tif', '*.jpg']\n            for p in preferred[::-1]:\n                if p in filter:\n                    filter.remove(p)\n                    filter.insert(0, p)\n            self.fileSaveDialog(filter=filter)\n            return\n            \n        targetRect = QtCore.QRect(0, 0, self.params['width'], self.params['height'])\n        sourceRect = self.getSourceRect()\n        \n        \n        #self.png = QtGui.QImage(targetRect.size(), QtGui.QImage.Format_ARGB32)\n        #self.png.fill(pyqtgraph.mkColor(self.params['background']))\n        w, h = self.params['width'], self.params['height']\n        if w == 0 or h == 0:\n            raise Exception(\"Cannot export image with size=0 (requested export size is %dx%d)\" % (w,h))\n        bg = np.empty((self.params['width'], self.params['height'], 4), dtype=np.ubyte)\n        color = self.params['background']\n        bg[:,:,0] = color.blue()\n        bg[:,:,1] = color.green()\n        bg[:,:,2] = color.red()\n        bg[:,:,3] = color.alpha()\n        self.png = fn.makeQImage(bg, alpha=True)\n        \n        ## set resolution of image:\n        origTargetRect = self.getTargetRect()\n        resolutionScale = targetRect.width() / origTargetRect.width()\n        #self.png.setDotsPerMeterX(self.png.dotsPerMeterX() * resolutionScale)\n        #self.png.setDotsPerMeterY(self.png.dotsPerMeterY() * resolutionScale)\n        \n        painter = QtGui.QPainter(self.png)\n        #dtr = painter.deviceTransform()\n        try:\n            self.setExportMode(True, {'antialias': self.params['antialias'], 'background': self.params['background'], 'painter': painter, 'resolutionScale': resolutionScale})\n            painter.setRenderHint(QtGui.QPainter.Antialiasing, self.params['antialias'])\n            self.getScene().render(painter, QtCore.QRectF(targetRect), QtCore.QRectF(sourceRect))\n        finally:\n            self.setExportMode(False)\n        painter.end()\n        \n        if copy:\n            QtGui.QApplication.clipboard().setImage(self.png)\n        elif toBytes:\n            return self.png\n        else:\n            self.png.save(fileName)\n        \nImageExporter.register()        \n        \n", "path": "pyqtgraph/exporters/ImageExporter.py"}]}