コード例 #1
0
ファイル: screenshot.py プロジェクト: Gerhut/web-rd
def get_data_uri():
    buffer = QBuffer()
    buffer.open(QIODevice.ReadWrite)

    QPixmap.grabWindow(QApplication.desktop().winId()).save(buffer, 'jpg', 10)
    
    return 'data:image/jpeg;base64,' + str(b64encode(buffer.data().data()), 'ascii')
コード例 #2
0
ファイル: spam_tests.py プロジェクト: samukaunt/deepbot-poker
def screenTable(library='xlib'):
    if (library=='xlib'):
        from Xlib import display, X
        ##Get screenshot of the table##
        width,height = int((1/2)*pyautogui.size().width/constants.NB_DISPLAYS),int((4/4)*pyautogui.size().height)
        dsp = display.Display()
        root = dsp.screen().root
        raw = root.get_image(0, 0, width, height, X.ZPixmap, 0xffffffff)
        table_img = Image.frombytes("RGB", (width, height), raw.data, "raw", "BGRX").convert('RGB')
        return table_img
    elif (library=='pyqt'):
        from PyQt4.QtGui import QPixmap, QApplication
        from PyQt4.Qt import QBuffer, QIODevice
        import io
        app = QApplication(sys.argv)
        buffer = QBuffer()
        buffer.open(QIODevice.ReadWrite)
        QPixmap.grabWindow(QApplication.desktop().winId()).save(buffer, 'png')
        strio = io.BytesIO()
        strio.write(buffer.data())
        buffer.close()
        del app
        strio.seek(0)
        table_img = Image.open(strio)
        width,height = int((1/2)*pyautogui.size().width/constants.NB_DISPLAYS),int((3/4)*pyautogui.size().height)
        table_img = table_img.crop((0,0,width,height))
       # print(table_img)
        return table_img

    else:
        print("The library: "+library+" can't be used here")
コード例 #3
0
ファイル: screen.py プロジェクト: Apkawa/screen_bot
    def get_screen_by_qt(self, x1=None, y1=None, x2=None, y2=None):
        from PyQt4.QtGui import QPixmap, QApplication
        from PyQt4.Qt import QBuffer, QIODevice
        import StringIO

        app = QApplication(sys.argv)
        _buffer = QBuffer()
        _buffer.open(QIODevice.ReadWrite)

        desktop = QApplication.desktop()
        #width = desktop.screenGeometry().width()
        #height = desktop.screenGeometry().height()

        if x1 is None:
            x1 = 0
        if y1 is None:
            y1 = 0
        if x2 is None:
            x2 = -1
        else:
            x2 -= x1
        if y2 is None:
            y2 = -1
        else:
            y2 -= y1

        QPixmap.grabWindow(desktop.winId(), x1, y1, x2, y2) \
                                    .save(_buffer, 'png')
        strio = StringIO.StringIO()
        strio.write(_buffer.data())
        _buffer.close()
        del app
        strio.seek(0)
        return Image.open(strio)
コード例 #4
0
    def getScreenByQt():

        buffer = QBuffer()
        buffer.open(QIODevice.ReadWrite)
        img = QPixmap.grabWindow(
            QApplication.desktop().winId()).toImage().copy(
                0, 0, 320, 240).convertToFormat(QImage.Format_RGB16)

        buf = bytearray(img.bits().asarray(320 * 240 * 2))

        # flip vertically
        offset = 320 * 240 * 2
        for i in range(0, 240 // 2):
            row_a = i
            row_b = 239 - i

            row_a_offset = 320 * row_a * 2
            row_b_offset = 320 * row_b * 2

            row_a_data = bytes(buf[row_a_offset:row_a_offset + 320 * 2])
            row_b_data = bytes(buf[row_b_offset:row_b_offset + 320 * 2])

            buf[row_a_offset:row_a_offset + 320 * 2] = row_b_data
            buf[row_b_offset:row_b_offset + 320 * 2] = row_a_data
        return buf
コード例 #5
0
 def __call__(self, ok):
     from PyQt4.Qt import QImage, QPainter, QByteArray, QBuffer
     try:
         if not ok:
             raise RuntimeError('Rendering of HTML failed.')
         de = self.page.mainFrame().documentElement()
         pe = de.findFirst('parsererror')
         if not pe.isNull():
             raise ParserError(pe.toPlainText())
         image = QImage(self.page.viewportSize(), QImage.Format_ARGB32)
         image.setDotsPerMeterX(96*(100/2.54))
         image.setDotsPerMeterY(96*(100/2.54))
         painter = QPainter(image)
         self.page.mainFrame().render(painter)
         painter.end()
         ba = QByteArray()
         buf = QBuffer(ba)
         buf.open(QBuffer.WriteOnly)
         image.save(buf, 'JPEG')
         self.data = str(ba.data())
     except Exception as e:
         self.exception = e
         self.traceback = traceback.format_exc()
     finally:
         self.loop.exit(0)
コード例 #6
0
    def applyFilter(self):
        # Konvertujem QImage do grayscale
        global frameBuffer
        imgBuffer = QBuffer()
        imgBuffer.open(QIODevice.ReadWrite)
        self.image.save(imgBuffer, "bmp")

        strio = cStringIO.StringIO()
        strio.write(imgBuffer.data())
        imgBuffer.close()
        strio.seek(0)
        pil_im = Image.open(strio).convert('L')

        # Pole v Numpy 8bit oer pixel
        numpyArray = np.asarray(pil_im)

        # Tu si urob filter nad polom
        numpyArray = fft(numpyArray)

        # koniec filtra, konvertujem obrazok nazad to QTimage
        pilOutput = Image.fromarray(numpyArray, 'L')

        if screenCaptureModifier.colorMap is not None:
            pilOutput.putpalette(screenCaptureModifier.colorMap)

        self.modifiedImage = ImageQt.ImageQt(pilOutput.convert('RGB'))
コード例 #7
0
class OpenGazer(object):

    def __init__(self, dir_pub, socket_opengazer_c):
        self.ctx_zmq = zmq.Context()
        self.socket = self.ctx_zmq.socket(zmq.PUB)
        self.socket.bind(dir_pub)
        self.socket_opengazer_c = socket_opengazer_c
        self.app = QApplication(sys.argv)
        self.buffer = QBuffer()

    def get_screen(self):
        self.buffer.open(QIODevice.ReadWrite)
        QPixmap.grabWindow(QApplication.desktop().winId()).scaled(480, 240).save(self.buffer, 'jpeg', quality=50)
        self.strio = StringIO()
        self.strio.write(self.buffer.data())
        self.buffer.close()
        self.strio.seek(0)

    def send_data(self):
        my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        my_socket.bind(("", self.socket_opengazer_c))
        print("socket creado")
        while True:
            data, addr = my_socket.recvfrom(self.socket_opengazer_c)
            self.get_screen()
            image_data = base64.b64encode(self.strio.getvalue())
            data_to_send = {'screen': image_data, 'x': int(data.split(' ')[0]),
                            'y': int(data.split(' ')[1]), 'target': int(data.split(' ')[2])}
            message = json.dumps(data_to_send)
            self.socket.send(message)
            #self.app.processEvents()
        my_socket.close()  # todo poner en finally
コード例 #8
0
ファイル: __init__.py プロジェクト: yeyanchao/calibre
 def __call__(self, ok):
     from PyQt4.Qt import QImage, QPainter, QByteArray, QBuffer
     try:
         if not ok:
             raise RuntimeError('Rendering of HTML failed.')
         de = self.page.mainFrame().documentElement()
         pe = de.findFirst('parsererror')
         if not pe.isNull():
             raise ParserError(pe.toPlainText())
         image = QImage(self.page.viewportSize(), QImage.Format_ARGB32)
         image.setDotsPerMeterX(96*(100/2.54))
         image.setDotsPerMeterY(96*(100/2.54))
         painter = QPainter(image)
         self.page.mainFrame().render(painter)
         painter.end()
         ba = QByteArray()
         buf = QBuffer(ba)
         buf.open(QBuffer.WriteOnly)
         image.save(buf, 'JPEG')
         self.data = str(ba.data())
     except Exception as e:
         self.exception = e
         self.traceback = traceback.format_exc()
     finally:
         self.loop.exit(0)
コード例 #9
0
ファイル: qtgrabwindow.py プロジェクト: hejibo/pyscreenshot
 def grab_to_buffer(self, buffer, file_type='png'):
     if not self.app:
         self.app = QApplication([])
     qbuffer = QBuffer()
     qbuffer.open(QIODevice.ReadWrite)
     QPixmap.grabWindow(QApplication.desktop().winId()).save(qbuffer, file_type)
     buffer.write(qbuffer.data())
     qbuffer.close()
コード例 #10
0
def pixmap_to_data(pixmap, format='JPEG', quality=90):
    '''
    Return the QPixmap pixmap as a string saved in the specified format.
    '''
    ba = QByteArray()
    buf = QBuffer(ba)
    buf.open(QBuffer.WriteOnly)
    pixmap.save(buf, format, quality=quality)
    return bytes(ba.data())
コード例 #11
0
ファイル: __init__.py プロジェクト: piewsook/calibre
def pixmap_to_data(pixmap, format='JPEG', quality=90):
    '''
    Return the QPixmap pixmap as a string saved in the specified format.
    '''
    ba = QByteArray()
    buf = QBuffer(ba)
    buf.open(QBuffer.WriteOnly)
    pixmap.save(buf, format, quality=quality)
    return bytes(ba.data())
コード例 #12
0
def image_to_data(image):  # {{{
    ba = QByteArray()
    buf = QBuffer(ba)
    buf.open(QBuffer.WriteOnly)
    if not image.save(buf, CACHE_FORMAT):
        raise EncodeError('Failed to encode thumbnail')
    ret = bytes(ba.data())
    buf.close()
    return ret
コード例 #13
0
ファイル: alternate_views.py プロジェクト: shamray/calibre
def image_to_data(image):  # {{{
    ba = QByteArray()
    buf = QBuffer(ba)
    buf.open(QBuffer.WriteOnly)
    if not image.save(buf, CACHE_FORMAT):
        raise EncodeError('Failed to encode thumbnail')
    ret = bytes(ba.data())
    buf.close()
    return ret
コード例 #14
0
ファイル: screencap.py プロジェクト: xbee/mypubsub
 def getScreenByQt(self):
     from PyQt4.QtGui import QPixmap, QApplication
     from PyQt4.Qt import QBuffer, QIODevice
     import StringIO
     app = QApplication(sys.argv)
     buffer = QBuffer()
     buffer.open(QIODevice.ReadWrite)
     QPixmap.grabWindow(QApplication.desktop().winId()).save(buffer, 'png')
     strio = StringIO.StringIO()
     strio.write(buffer.data())
     buffer.close()
     del app
     strio.seek(0)
     return Image.open(strio)
コード例 #15
0
ファイル: screenshot.py プロジェクト: SamuelDeleglise/dmqh
 def getScreenByQt(self):
     from PyQt4.QtGui import QPixmap, QApplication
     from PyQt4.Qt import QBuffer, QIODevice
     import StringIO
     app = QApplication(sys.argv)
     buffer = QBuffer()
     buffer.open(QIODevice.ReadWrite)
     QPixmap.grabWindow(QApplication.desktop().winId()).save(buffer, 'png')
     strio = StringIO.StringIO()
     strio.write(buffer.data())
     buffer.close()
     del app
     strio.seek(0)
     return Image.open(strio)
コード例 #16
0
 def getScreenByQt(self):
     from PyQt4.QtGui import QPixmap, QApplication
     from PyQt4.Qt import QBuffer, QIODevice
     import StringIO
     # there should only ever be a single instance of QApplication or else it crashes on some platforms
     if Screenshot.qtAppInstance is None:
         Screenshot.qtAppInstance = QApplication(sys.argv)
     buffer = QBuffer()
     buffer.open(QIODevice.ReadWrite)
     QPixmap.grabWindow(QApplication.desktop().winId()).save(buffer, 'png')
     strio = StringIO.StringIO()
     strio.write(buffer.data())
     buffer.close()
     strio.seek(0)
     return Image.open(strio)
コード例 #17
0
 def getScreenByQt4(self):
    from PyQt4.Qt import QBuffer
    import StringIO
    from PyQt4.Qt import QIODevice
    from PyQt4.QtGui import QPixmap
    from PyQt4.QtGui import QApplication
    buffer = QBuffer()
    rootwin = QApplication.desktop().winId()
    buffer.open(QIODevice.ReadWrite)
    strio = StringIO.StringIO()
    QPixmap.grabWindow(rootwin).save(buffer, 'jpg')
    strio.write(buffer.data())
    strio.seek(0)
    buffer.close()
    return Image.open(strio)
コード例 #18
0
ファイル: graphwidgets.py プロジェクト: guenp/colorgraphs
    def _repr_png_(self):
        self.show()
        self.hide()
        if not self.btn.visible:
            display(self.btn)
            self.btn.visible = True

        mainExp = ImageExporter(self.plotItem)
        self.image = mainExp.export(toBytes=True)

        byte_array = QByteArray()
        buffer = QBuffer(byte_array)
        buffer.open(QIODevice.ReadWrite)
        self.image.save(buffer, 'PNG')
        buffer.close()

        return bytes(byte_array)
コード例 #19
0
 def _save(self):
     self.checkPrice
     self.itemName=self.window.le_ItemName.text()
     if self.itemName=="" or self.itemPrice==0 or self.itemIcon is None:
         message=u"Не все данные указаны"
         self._showMessage(u'Ошибка', message)
         self.window.btn_Save.setEnabled(False)
         return
     blobImg=QByteArray()
     buff=QBuffer(blobImg)
     buff.open(QBuffer.WriteOnly)
     
     self.itemIcon.save(buff, "JPG")
     if self.typeOperation=='Add':
         self.addItem(blobImg)
     elif self.typeOperation=='Edit':
         self.editItem(blobImg) 
     self.window.close()
     self.emit(QtCore.SIGNAL("RefreshItemTable"))
コード例 #20
0
ファイル: peek.py プロジェクト: dkkline/PyPeek
def peek_qt(fmt="png"):
    """Takes a screenshot using QT."""
    import sys
    from PyQt4.QtGui import QPixmap, QApplication
    from PyQt4.Qt import QBuffer, QIODevice

    app = QApplication(sys.argv)
    buff = QBuffer()
    buff.open(QIODevice.ReadWrite)
    QPixmap.grabWindow(QApplication.desktop().winId()).save(buff, fmt)

    screenshot = Screenshot()
    screenshot.addvalue(buff.data())
    buff.close()
    del app

    screenshot.fmt = fmt

    return screenshot
コード例 #21
0
ファイル: __init__.py プロジェクト: siebert/calibre
def to_png(bmp):
    # ImageMagick does not convert some bmp files correctly, while Qt does,
    # so try Qt first. See for instance:
    # https://bugs.launchpad.net/calibre/+bug/934167
    # ImageMagick bug report:
    # http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=20350
    from PyQt4.Qt import QImage, QByteArray, QBuffer
    i = QImage()
    if i.loadFromData(bmp):
        ba = QByteArray()
        buf = QBuffer(ba)
        buf.open(QBuffer.WriteOnly)
        i.save(buf, 'png')
        return bytes(ba.data())

    from calibre.utils.magick import Image
    img = Image()
    img.load(bmp)
    return img.export('png')
コード例 #22
0
ファイル: __init__.py プロジェクト: hashken/calibre
def to_png(bmp):
    # ImageMagick does not convert some bmp files correctly, while Qt does,
    # so try Qt first. See for instance:
    # https://bugs.launchpad.net/calibre/+bug/934167
    # ImageMagick bug report:
    # http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=20350
    from PyQt4.Qt import QImage, QByteArray, QBuffer

    i = QImage()
    if i.loadFromData(bmp):
        ba = QByteArray()
        buf = QBuffer(ba)
        buf.open(QBuffer.WriteOnly)
        i.save(buf, "png")
        return bytes(ba.data())

    from calibre.utils.magick import Image

    img = Image()
    img.load(bmp)
    return img.export("png")
コード例 #23
0
ファイル: graphwidgets.py プロジェクト: guenp/colorgraphs
    def _repr_png_(self):
        if not self.in_dock():
            self.show()
            self.hide()
        else:
            self.window().show()
            self.window().hide()

        if not self.btn.visible:
            display(self.btn)
            self.btn.visible = True

        QtGui.QApplication.processEvents()
        
        self.image = self.getQImage()

        byte_array = QByteArray()
        buffer = QBuffer(byte_array)
        buffer.open(QIODevice.ReadWrite)
        self.image.save(buffer, 'PNG')
        buffer.close()
        return bytes(byte_array)
コード例 #24
0
ファイル: plotter.py プロジェクト: ntbrewer/Pyspeqtr
    def _repr_png_(self):

        self._widget.hide()

        QtGui.QApplication.processEvents()
        
        try:
            self.image = QImage(self._widget.viewRect().size().toSize(),
                                QImage.Format_RGB32)
        except AttributeError:
            self._widget.updateGL()
            self.image = self._widget.grabFrameBuffer()
            
        painter = QPainter(self.image)
        self._widget.render(painter)

        byte_array = QByteArray()
        buffer = QBuffer(byte_array)
        buffer.open(QIODevice.ReadWrite)
        self.image.save(buffer, 'PNG')
        buffer.close()        

        return bytes(byte_array)
コード例 #25
0
    def _repr_png_(self):

        self._widget.hide()

        QtGui.QApplication.processEvents()

        try:
            self.image = QImage(self._widget.viewRect().size().toSize(),
                                QImage.Format_RGB32)
        except AttributeError:
            self._widget.updateGL()
            self.image = self._widget.grabFrameBuffer()

        painter = QPainter(self.image)
        self._widget.render(painter)

        byte_array = QByteArray()
        buffer = QBuffer(byte_array)
        buffer.open(QIODevice.ReadWrite)
        self.image.save(buffer, 'PNG')
        buffer.close()

        return bytes(byte_array)
コード例 #26
0
class OpenGazer(object):
    def __init__(self, dir_pub, socket_opengazer_c):
        self.ctx_zmq = zmq.Context()
        self.socket = self.ctx_zmq.socket(zmq.PUB)
        self.socket.bind(dir_pub)
        self.socket_opengazer_c = socket_opengazer_c
        self.app = QApplication(sys.argv)
        self.buffer = QBuffer()

    def get_screen(self):
        self.buffer.open(QIODevice.ReadWrite)
        QPixmap.grabWindow(QApplication.desktop().winId()).scaled(
            480, 240).save(self.buffer, 'jpeg', quality=50)
        self.strio = StringIO()
        self.strio.write(self.buffer.data())
        self.buffer.close()
        self.strio.seek(0)

    def send_data(self):
        my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        my_socket.bind(("", self.socket_opengazer_c))
        print("socket creado")
        while True:
            data, addr = my_socket.recvfrom(self.socket_opengazer_c)
            self.get_screen()
            image_data = base64.b64encode(self.strio.getvalue())
            data_to_send = {
                'screen': image_data,
                'x': int(data.split(' ')[0]),
                'y': int(data.split(' ')[1]),
                'target': int(data.split(' ')[2])
            }
            message = json.dumps(data_to_send)
            self.socket.send(message)
            #self.app.processEvents()
        my_socket.close()  # todo poner en finally