Python wx.BITMAP_TYPE_JPEG Examples

The following are 17 code examples of wx.BITMAP_TYPE_JPEG(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: chronolapse.py    From chronolapse with MIT License 6 votes vote down vote up
def saveImage(self, bmp, filename, folder, prefix, format='jpg'):
        # convert
        img = bmp.ConvertToImage()

        # save
        if format == 'gif':
            fileName = os.path.join(folder,"%s%s.gif" % (prefix, filename))
            img.SaveFile(fileName, wx.BITMAP_TYPE_GIF)

        elif format == 'png':
            fileName = os.path.join(folder,"%s%s.png" % (prefix, filename))
            img.SaveFile(fileName, wx.BITMAP_TYPE_PNG)

        else:
            fileName = os.path.join(folder,"%s%s.jpg" % (prefix, filename))
            img.SaveFile(fileName, wx.BITMAP_TYPE_JPEG) 
Example #2
Source File: backend_wx.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG,
                                     *args, **kwargs) 
Example #3
Source File: backend_wx.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG,
                                     *args, **kwargs) 
Example #4
Source File: backend_wx.py    From CogAlg with MIT License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG,
                                     *args, **kwargs) 
Example #5
Source File: backend_wx.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG,
                                     *args, **kwargs) 
Example #6
Source File: backend_wx.py    From ImageFusion with MIT License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG, *args, **kwargs) 
Example #7
Source File: backend_wx.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG,
                                     *args, **kwargs) 
Example #8
Source File: backend_wx.py    From Computable with MIT License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG, *args, **kwargs) 
Example #9
Source File: backend_wx.py    From neural-network-animation with MIT License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG, *args, **kwargs) 
Example #10
Source File: backend_wx.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG, *args, **kwargs) 
Example #11
Source File: backend_wx.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def print_jpeg(self, filename, *args, **kwargs):
            return self._print_image(filename, wx.BITMAP_TYPE_JPEG,
                                     *args, **kwargs) 
Example #12
Source File: backend_wx.py    From neural-network-animation with MIT License 4 votes vote down vote up
def _print_image(self, filename, filetype, *args, **kwargs):
        origBitmap   = self.bitmap

        l,b,width,height = self.figure.bbox.bounds
        width = int(math.ceil(width))
        height = int(math.ceil(height))

        self.bitmap = wx.EmptyBitmap(width, height)
        renderer = RendererWx(self.bitmap, self.figure.dpi)

        gc = renderer.new_gc()

        self.figure.draw(renderer)

        # image is the object that we call SaveFile on.
        image = self.bitmap
        # set the JPEG quality appropriately.  Unfortunately, it is only possible
        # to set the quality on a wx.Image object.  So if we are saving a JPEG,
        # convert the wx.Bitmap to a wx.Image, and set the quality.
        if filetype == wx.BITMAP_TYPE_JPEG:
           jpeg_quality = kwargs.get('quality',rcParams['savefig.jpeg_quality'])
           image = self.bitmap.ConvertToImage()
           image.SetOption(wx.IMAGE_OPTION_QUALITY,str(jpeg_quality))

        # Now that we have rendered into the bitmap, save it
        # to the appropriate file type and clean up
        if is_string_like(filename):
            if not image.SaveFile(filename, filetype):
                DEBUG_MSG('print_figure() file save error', 4, self)
                raise RuntimeError('Could not save figure to %s\n' % (filename))
        elif is_writable_file_like(filename):
            if not isinstance(image,wx.Image):
               image = image.ConvertToImage()
            if not image.SaveStream(filename, filetype):
                DEBUG_MSG('print_figure() file save error', 4, self)
                raise RuntimeError('Could not save figure to %s\n' % (filename))

        # Restore everything to normal
        self.bitmap = origBitmap

        # Note: draw is required here since bits of state about the
        # last renderer are strewn about the artist draw methods.  Do
        # not remove the draw without first verifying that these have
        # been cleaned up.  The artist contains() methods will fail
        # otherwise.
        if self._isDrawn:
            self.draw()
        self.Refresh() 
Example #13
Source File: backend_wx.py    From matplotlib-4-abaqus with MIT License 4 votes vote down vote up
def _print_image(self, filename, filetype, *args, **kwargs):
        origBitmap   = self.bitmap

        l,b,width,height = self.figure.bbox.bounds
        width = int(math.ceil(width))
        height = int(math.ceil(height))

        self.bitmap = wx.EmptyBitmap(width, height)
        renderer = RendererWx(self.bitmap, self.figure.dpi)

        gc = renderer.new_gc()

        self.figure.draw(renderer)

        # image is the object that we call SaveFile on.
        image = self.bitmap
        # set the JPEG quality appropriately.  Unfortunately, it is only possible
        # to set the quality on a wx.Image object.  So if we are saving a JPEG,
        # convert the wx.Bitmap to a wx.Image, and set the quality.
        if filetype == wx.BITMAP_TYPE_JPEG:
           jpeg_quality = kwargs.get('quality',rcParams['savefig.jpeg_quality'])
           image = self.bitmap.ConvertToImage()
           image.SetOption(wx.IMAGE_OPTION_QUALITY,str(jpeg_quality))

        # Now that we have rendered into the bitmap, save it
        # to the appropriate file type and clean up
        if is_string_like(filename):
            if not image.SaveFile(filename, filetype):
                DEBUG_MSG('print_figure() file save error', 4, self)
                raise RuntimeError('Could not save figure to %s\n' % (filename))
        elif is_writable_file_like(filename):
            if not isinstance(image,wx.Image):
               image = image.ConvertToImage()
            if not image.SaveStream(filename, filetype):
                DEBUG_MSG('print_figure() file save error', 4, self)
                raise RuntimeError('Could not save figure to %s\n' % (filename))

        # Restore everything to normal
        self.bitmap = origBitmap

        # Note: draw is required here since bits of state about the
        # last renderer are strewn about the artist draw methods.  Do
        # not remove the draw without first verifying that these have
        # been cleaned up.  The artist contains() methods will fail
        # otherwise.
        if self._isDrawn:
            self.draw()
        self.Refresh() 
Example #14
Source File: backend_wx.py    From ImageFusion with MIT License 4 votes vote down vote up
def _print_image(self, filename, filetype, *args, **kwargs):
        origBitmap   = self.bitmap

        l,b,width,height = self.figure.bbox.bounds
        width = int(math.ceil(width))
        height = int(math.ceil(height))

        self.bitmap = wx.EmptyBitmap(width, height)
        renderer = RendererWx(self.bitmap, self.figure.dpi)

        gc = renderer.new_gc()

        self.figure.draw(renderer)

        # image is the object that we call SaveFile on.
        image = self.bitmap
        # set the JPEG quality appropriately.  Unfortunately, it is only possible
        # to set the quality on a wx.Image object.  So if we are saving a JPEG,
        # convert the wx.Bitmap to a wx.Image, and set the quality.
        if filetype == wx.BITMAP_TYPE_JPEG:
           jpeg_quality = kwargs.get('quality',rcParams['savefig.jpeg_quality'])
           image = self.bitmap.ConvertToImage()
           image.SetOption(wx.IMAGE_OPTION_QUALITY,str(jpeg_quality))

        # Now that we have rendered into the bitmap, save it
        # to the appropriate file type and clean up
        if is_string_like(filename):
            if not image.SaveFile(filename, filetype):
                DEBUG_MSG('print_figure() file save error', 4, self)
                raise RuntimeError('Could not save figure to %s\n' % (filename))
        elif is_writable_file_like(filename):
            if not isinstance(image,wx.Image):
               image = image.ConvertToImage()
            if not image.SaveStream(filename, filetype):
                DEBUG_MSG('print_figure() file save error', 4, self)
                raise RuntimeError('Could not save figure to %s\n' % (filename))

        # Restore everything to normal
        self.bitmap = origBitmap

        # Note: draw is required here since bits of state about the
        # last renderer are strewn about the artist draw methods.  Do
        # not remove the draw without first verifying that these have
        # been cleaned up.  The artist contains() methods will fail
        # otherwise.
        if self._isDrawn:
            self.draw()
        self.Refresh() 
Example #15
Source File: backend_wx.py    From Mastering-Elasticsearch-7.0 with MIT License 4 votes vote down vote up
def _print_image(self, filename, filetype, *args, **kwargs):
        origBitmap = self.bitmap

        l, b, width, height = self.figure.bbox.bounds
        width = math.ceil(width)
        height = math.ceil(height)

        self.bitmap = wx.Bitmap(width, height)

        renderer = RendererWx(self.bitmap, self.figure.dpi)

        gc = renderer.new_gc()

        self.figure.draw(renderer)

        # image is the object that we call SaveFile on.
        image = self.bitmap
        # set the JPEG quality appropriately.  Unfortunately, it is only
        # possible to set the quality on a wx.Image object.  So if we
        # are saving a JPEG, convert the wx.Bitmap to a wx.Image,
        # and set the quality.
        if filetype == wx.BITMAP_TYPE_JPEG:
            jpeg_quality = kwargs.get('quality',
                                      rcParams['savefig.jpeg_quality'])
            image = self.bitmap.ConvertToImage()
            image.SetOption(wx.IMAGE_OPTION_QUALITY, str(jpeg_quality))

        # Now that we have rendered into the bitmap, save it to the appropriate
        # file type and clean up.
        if isinstance(filename, str):
            if not image.SaveFile(filename, filetype):
                raise RuntimeError(f'Could not save figure to {filename}')
        elif cbook.is_writable_file_like(filename):
            if not isinstance(image, wx.Image):
                image = image.ConvertToImage()
            if not image.SaveStream(filename, filetype):
                raise RuntimeError(f'Could not save figure to {filename}')

        # Restore everything to normal
        self.bitmap = origBitmap

        # Note: draw is required here since bits of state about the
        # last renderer are strewn about the artist draw methods.  Do
        # not remove the draw without first verifying that these have
        # been cleaned up.  The artist contains() methods will fail
        # otherwise.
        if self._isDrawn:
            self.draw()
        self.Refresh()


########################################################################
#
# The following functions and classes are for pylab compatibility
# mode (matplotlib.pylab) and implement figure managers, etc...
#
######################################################################## 
Example #16
Source File: backend_wx.py    From CogAlg with MIT License 4 votes vote down vote up
def _print_image(self, filename, filetype, *args, **kwargs):
        origBitmap = self.bitmap

        l, b, width, height = self.figure.bbox.bounds
        width = math.ceil(width)
        height = math.ceil(height)

        self.bitmap = wx.Bitmap(width, height)

        renderer = RendererWx(self.bitmap, self.figure.dpi)

        gc = renderer.new_gc()

        self.figure.draw(renderer)

        # image is the object that we call SaveFile on.
        image = self.bitmap
        # set the JPEG quality appropriately.  Unfortunately, it is only
        # possible to set the quality on a wx.Image object.  So if we
        # are saving a JPEG, convert the wx.Bitmap to a wx.Image,
        # and set the quality.
        if filetype == wx.BITMAP_TYPE_JPEG:
            jpeg_quality = kwargs.get('quality',
                                      rcParams['savefig.jpeg_quality'])
            image = self.bitmap.ConvertToImage()
            image.SetOption(wx.IMAGE_OPTION_QUALITY, str(jpeg_quality))

        # Now that we have rendered into the bitmap, save it to the appropriate
        # file type and clean up.
        if isinstance(filename, str):
            if not image.SaveFile(filename, filetype):
                raise RuntimeError(f'Could not save figure to {filename}')
        elif cbook.is_writable_file_like(filename):
            if not isinstance(image, wx.Image):
                image = image.ConvertToImage()
            if not image.SaveStream(filename, filetype):
                raise RuntimeError(f'Could not save figure to {filename}')

        # Restore everything to normal
        self.bitmap = origBitmap

        # Note: draw is required here since bits of state about the
        # last renderer are strewn about the artist draw methods.  Do
        # not remove the draw without first verifying that these have
        # been cleaned up.  The artist contains() methods will fail
        # otherwise.
        if self._isDrawn:
            self.draw()
        self.Refresh()


########################################################################
#
# The following functions and classes are for pylab compatibility
# mode (matplotlib.pylab) and implement figure managers, etc...
#
######################################################################## 
Example #17
Source File: backend_wx.py    From Computable with MIT License 4 votes vote down vote up
def _print_image(self, filename, filetype, *args, **kwargs):
        origBitmap   = self.bitmap

        l,b,width,height = self.figure.bbox.bounds
        width = int(math.ceil(width))
        height = int(math.ceil(height))

        self.bitmap = wx.EmptyBitmap(width, height)
        renderer = RendererWx(self.bitmap, self.figure.dpi)

        gc = renderer.new_gc()

        self.figure.draw(renderer)

        # image is the object that we call SaveFile on.
        image = self.bitmap
        # set the JPEG quality appropriately.  Unfortunately, it is only possible
        # to set the quality on a wx.Image object.  So if we are saving a JPEG,
        # convert the wx.Bitmap to a wx.Image, and set the quality.
        if filetype == wx.BITMAP_TYPE_JPEG:
           jpeg_quality = kwargs.get('quality',rcParams['savefig.jpeg_quality'])
           image = self.bitmap.ConvertToImage()
           image.SetOption(wx.IMAGE_OPTION_QUALITY,str(jpeg_quality))

        # Now that we have rendered into the bitmap, save it
        # to the appropriate file type and clean up
        if is_string_like(filename):
            if not image.SaveFile(filename, filetype):
                DEBUG_MSG('print_figure() file save error', 4, self)
                raise RuntimeError('Could not save figure to %s\n' % (filename))
        elif is_writable_file_like(filename):
            if not isinstance(image,wx.Image):
               image = image.ConvertToImage()
            if not image.SaveStream(filename, filetype):
                DEBUG_MSG('print_figure() file save error', 4, self)
                raise RuntimeError('Could not save figure to %s\n' % (filename))

        # Restore everything to normal
        self.bitmap = origBitmap

        # Note: draw is required here since bits of state about the
        # last renderer are strewn about the artist draw methods.  Do
        # not remove the draw without first verifying that these have
        # been cleaned up.  The artist contains() methods will fail
        # otherwise.
        if self._isDrawn:
            self.draw()
        self.Refresh()