当前位置: 首页>>代码示例>>Python>>正文


Python QBuffer.open方法代码示例

本文整理汇总了Python中PyQt4.QtCore.QBuffer.open方法的典型用法代码示例。如果您正苦于以下问题:Python QBuffer.open方法的具体用法?Python QBuffer.open怎么用?Python QBuffer.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtCore.QBuffer的用法示例。


在下文中一共展示了QBuffer.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: screenshot

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
    def screenshot(self):
        logging.debug('screenshot() invoked')

        frame = self.page().mainFrame()
        size = frame.contentsSize()

        if (self.screenWidth):
           size.setWidth(self.screenWidth)

        if (self.screenHeight):
           size.setHeight(self.screenHeight)

        if (self.minWidth and self.minWidth > self.screenWidth):
           size.setWidth(self.minWidth)

        if (self.minHeight and self.minHeight > self.screenHeight):
           size.setHeight(self.minHeight)

        self.page().setViewportSize(size)
        image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
        painter = QPainter(image)
        frame.render(painter)
        painter.end()

        buffer = QBuffer()
        buffer.open(QIODevice.ReadWrite)
        image.save(buffer, self.format, self.quality)

        logging.debug('screenshot() returned image of type ' + self.content_type + ' of length ' + str(buffer.data().length()))
        
        return { 'content': buffer.data(), 'content_type': self.content_type }
开发者ID:joelbeckham,项目名称:ss,代码行数:33,代码来源:screenshot.py

示例2: __init__

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
    def __init__(self):
        QWidget.__init__(self)
        self.tray = Tray(self)
        self.setMinimumSize(QSize(320, 200))
        self.setWindowFlags(Qt.Popup|Qt.FramelessWindowHint)
        self.verticalLayout = QVBoxLayout(self)
        self.verticalLayout.setMargin(1)

        self.text = QTextBrowser(self)
        self.text.setReadOnly(True)
        self.text.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.text.setOpenExternalLinks(True)
        self.verticalLayout.addWidget(self.text)
        self.text.textChanged.connect(self.on_text_changed)
        self.notify = Notify(self)

        self.movie = QMovie()
        dev = QBuffer()
        dev.setData(QByteArray.fromBase64(CHECK_IMAGE))
        dev.open(QBuffer.ReadOnly)
        dev.setParent(self.movie)
        self.movie.setDevice(dev)
        self.movie.frameChanged.connect(self.on_frame_changed)

        self.realized = False
        self.show()
开发者ID:gen2brain,项目名称:gmailcheck,代码行数:28,代码来源:gmailcheck.py

示例3: from_QImage

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
 def from_QImage(self, img):
     buf = QByteArray()
     bf = QBuffer(buf)
     bf.open(QIODevice.WriteOnly)
     img.save(bf, format='PNG')
     self.buf = buf.data()
     self.format = PackedQImage.FORMAT_PNG
     self._encode()
开发者ID:jonathanverner,项目名称:qidle,代码行数:10,代码来源:printhooks.py

示例4: newfunc

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
 def newfunc():
     ba = QByteArray(data)  # keep reference to avoid GC
     f = QBuffer(ba)
     f.open(mode)
     try:
         func(f)
     finally:
         f.close()
开发者ID:velorientc,项目名称:git_test7,代码行数:10,代码来源:qt_repotreemodel_test.py

示例5: get_html_img

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
def get_html_img(scene):
    """
    Create HTML img element with base64-encoded image from the scene
    """
    byte_array = QByteArray()
    filename = QBuffer(byte_array)
    filename.open(QIODevice.WriteOnly)
    PngFormat.write(filename, scene)
    img_encoded = byte_array.toBase64().data().decode("utf-8")
    return "<img src='data:image/png;base64,%s'/>" % img_encoded
开发者ID:JingqinGao,项目名称:orange3,代码行数:12,代码来源:report.py

示例6: pixmap_to_imgformat

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
def pixmap_to_imgformat(pixmap, format):
    import io
    from PyQt4.QtCore import QBuffer, QByteArray, QIODevice

    byte_array = QByteArray()
    buffer = QBuffer(byte_array)
    buffer.open(QIODevice.WriteOnly)
    pixmap.save(buffer, format)
    string_io = io.BytesIO(byte_array)
    string_io.seek(0)
    return string_io.read()
开发者ID:ov1d1u,项目名称:cyuf,代码行数:13,代码来源:util.py

示例7: getImage

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
    def getImage(self):
        """ Return the loaded image """
        if self.isDefault:
            return None

        pix = self.orignalimage
        by = QByteArray()
        buf = QBuffer(by)
        buf.open(QIODevice.WriteOnly)
        pix.save(buf, "JPG")
        return by
开发者ID:tudorbarascu,项目名称:Roam,代码行数:13,代码来源:imagewidget.py

示例8: render_layers

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
def render_layers(layer_paths):
    """

    :param layer_paths: A list of layer paths.
    :return: Buffer containing output. Note caller is responsible for closing
        the buffer with buffer.close()
    :rtype: QBuffer
    """
    layers = []
    extent = None


    crs = QgsCoordinateReferenceSystem()
    crs.createFromSrid(3857)

    for layer_path in layer_paths:
        map_layer = QgsVectorLayer(layer_path, None, 'ogr')
        QgsMapLayerRegistry.instance().addMapLayer(map_layer)
        transform = QgsCoordinateTransform(map_layer.crs(), crs)
        print map_layer.extent().toString()
        layer_extent = transform.transform(map_layer.extent())
        if extent is None:
            extent = layer_extent
        else:
            extent.combineExtentWith(layer_extent)
        print extent.toString()
        # set layer set
        layers.append(map_layer.id())  # add ID of every layer

    map_settings = QgsMapSettings()

    map_settings.setDestinationCrs(crs)
    map_settings.setCrsTransformEnabled(True)
    map_settings.setExtent(extent)
    map_settings.setOutputSize(QSize(1000, 1000))

    map_settings.setLayers(layers)

    # job = QgsMapRendererParallelJob(settings)
    job = QgsMapRendererSequentialJob(map_settings)
    job.start()
    job.waitForFinished()
    image = job.renderedImage()
    # Save teh image to a buffer
    map_buffer = QBuffer()
    map_buffer.open(QIODevice.ReadWrite)
    image.save(map_buffer, "PNG")
    image.save('/tmp/test.png', 'png')

    # clean up
    QgsMapLayerRegistry.instance().removeAllMapLayers()

    return map_buffer
开发者ID:timlinux,项目名称:webandgis,代码行数:55,代码来源:views.py

示例9: saveTiles

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
  def saveTiles(self):
    if self.tiles is None:
      QMessageBox.warning(None, self.plugin.pluginName, self.tr("No tiles have been downloaded."))
      return

    # Let the user choose the directory to save to
    directory = QFileDialog.getExistingDirectory(caption=self.tr("{}: Choose directory").format(self.layerDef.title))
    if not directory:
      # User cancelled the directory selection
      return

    # Build the content of the .aux.xml file containing the projection info
    projection_string = (self.crs().toWkt())
    pam_string = '<PAMDataset>\n' + \
                 '<SRS>{}</SRS>\n'.format(projection_string) + \
                 '</PAMDataset>'

    for tile in self.tiles.tiles.values():
      # Figure out the file format extension
      reader = QImageReader()
      buffer = QBuffer()
      buffer.setData(tile.data)
      buffer.open(QIODevice.ReadOnly)
      extension = str(reader.imageFormat(buffer))

      # Build the file name of the image file
      image_file_name = "{}-{}-{}.{}".format(tile.x, tile.y, tile.zoom, extension)
      image_file_path = join(directory, image_file_name)

      # Save the image file
      with open(image_file_path, 'wb') as image_file:
        image_file.write(tile.data)

      # Save the .aux.xml
      with open(image_file_path + '.aux.xml', 'w') as aux_file:
        aux_file.write(pam_string)

      # Save the world file containing the georeferencing information
      tile_rect = self.tiles.serviceInfo.getTileRect(tile.zoom, tile.x, tile.y)
      tile_size = self.tiles.TILE_SIZE
      with open(image_file_path + 'w', 'w') as world_file:
        world_file.writelines([
          str(tile_rect.width() / tile_size) + '\n',
          '0\n',
          '0\n',
          str(-tile_rect.height() / tile_size) + '\n',
          str(tile_rect.xMinimum()) + '\n',
          str(tile_rect.yMaximum()) + '\n'
        ])

    # Done
    msg = self.tr("Tiles have been saved.")
    self.showMessageBar(msg, QgsMessageBar.INFO, 2)
开发者ID:minorua,项目名称:TileLayerPlugin,代码行数:55,代码来源:tilelayer.py

示例10: QIm2PIL

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
def QIm2PIL(qimg):
    buff = QBuffer()
    buff.open(QIODevice.WriteOnly)
    qimg.save(buff, 'BMP')
    fp = StringIO()
    fp.write(buff.data())
    buff.close()
    fp.seek(0)
    pilimg = Image.open(fp)
    if pilimg.mode == 'P':
        return pilimg.convert('L')
    return pilimg
开发者ID:polzuka,项目名称:inspirado,代码行数:14,代码来源:transformer.py

示例11: OCRperformOCRName

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
def OCRperformOCRName(position,x,y,w,h,digits = False):
	img = QPixmap.grabWindow(QApplication.desktop().winId(),x,y,w,h)
	#img.save('a.png', 'png')
	buffer = QBuffer()
	buffer.open(QIODevice.ReadWrite)
	img.save(buffer, "PNG")
	
	strio = cStringIO.StringIO()
	strio.write(buffer.data())
	buffer.close()
	strio.seek(0)
	im = Image.open(strio)
	pixdata = im.load();
	
	for y in xrange(im.size[1]):
		for x in xrange(im.size[0]):
			total = pixdata[x, y][0] + pixdata[x, y][1] + pixdata[x, y][2]
			if total < 500:
				pixdata[x, y] = (255, 255, 255)
			else:
				pixdata[x, y] = (0, 0, 0)
				
	#Add extra space on each side
	for y in xrange(im.size[1]):
		pixdata[0,y] = (255, 255, 255)
		pixdata[1,y] = (255, 255, 255)
		pixdata[im.size[0]-1,y] = (255, 255, 255)
		pixdata[im.size[0]-2,y] = (255, 255, 255)
	for x in xrange(im.size[0]):
		pixdata[x,0] = (255, 255, 255)
		pixdata[x,1] = (255, 255, 255)
		pixdata[x,im.size[1]-1] = (255, 255, 255)
		pixdata[x,im.size[1]-2] = (255, 255, 255)
		
	nx, ny = im.size
	im = im.resize((nx*5, ny*5), Image.ANTIALIAS)
	enh = ImageEnhance.Contrast(im)
	pixdata = im.load()
	for y in xrange(im.size[1]):
		for x in xrange(im.size[0]):
			total = pixdata[x, y][0] + pixdata[x, y][1] + pixdata[x, y][2]
			if total < 500:
				pixdata[x, y] = (0, 0, 0)
			else:
				pixdata[x, y] = (255, 255, 255)	
	im = im.resize((int(nx*5), int(ny*5)), Image.BILINEAR)
	rvalue = OCR_to_string(im,digits)
	#im.save("training"+str(position)+""+str(int(random.random()*10000)) +".png","PNG")
	return rvalue 
开发者ID:LiutaurasP,项目名称:Python-workground,代码行数:51,代码来源:SuckerZoom.py

示例12: capture_image

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
def capture_image(session, selector=None, outformat="jpg"):
    """ capture page as image """

    # do capture now
    cap = None
    if selector is not None:
        cap = session.capture(selector=selector)
    else:
        cap = session.capture()

    # create a buffered image
    buffer = QBuffer()
    buffer.open(QIODevice.ReadWrite)
    cap.save(buffer, 'JPG' if outformat.upper() in ('JPG', 'JPEG') else 'PNG')
    buffer.close()
    return buffer, 'image/' + 'jpeg' if outformat.upper() in ('JPG','JPEG') else 'png'
开发者ID:metal3d,项目名称:belphegor,代码行数:18,代码来源:main.py

示例13: capture_to_buf

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
    def capture_to_buf(self, selector=None):
        """capture the images of selector to StringIO

        @param selector: Css selector.
        @return: The StringIO list.
        """

        images = self.capture(selector)
        result = []

        for image in images:
            ba = QByteArray()
            buf = QBuffer(ba)
            buf.open(QIODevice.ReadWrite)
            image.save(buf, 'jpg')
            stream = StringIO(str(buf.buffer()))
            result.append(stream)

        return result
开发者ID:whitelok,项目名称:LandofBitCoinMonitor,代码行数:21,代码来源:GRobot.py

示例14: rasterize_svg

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
    def rasterize_svg(self, elem, width=0, height=0, format='PNG'):
        view_box = elem.get('viewBox', elem.get('viewbox', None))
        sizes = None
        logger = self.oeb.logger

        if view_box is not None:
            try:
                box = [float(x) for x in filter(None, re.split('[, ]', view_box))]
                sizes = [box[2]-box[0], box[3] - box[1]]
            except (TypeError, ValueError, IndexError):
                logger.warn('SVG image has invalid viewBox="%s", ignoring the viewBox' % view_box)
            else:
                for image in elem.xpath('descendant::*[local-name()="image" and '
                        '@height and contains(@height, "%")]'):
                    logger.info('Found SVG image height in %, trying to convert...')
                    try:
                        h = float(image.get('height').replace('%', ''))/100.
                        image.set('height', str(h*sizes[1]))
                    except:
                        logger.exception('Failed to convert percentage height:',
                                image.get('height'))

        data = QByteArray(xml2str(elem, with_tail=False))
        svg = QSvgRenderer(data)
        size = svg.defaultSize()
        if size.width() == 100 and size.height() == 100 and sizes:
            size.setWidth(sizes[0])
            size.setHeight(sizes[1])
        if width or height:
            size.scale(width, height, Qt.KeepAspectRatio)
        logger.info('Rasterizing %r to %dx%d'
                    % (elem, size.width(), size.height()))
        image = QImage(size, QImage.Format_ARGB32_Premultiplied)
        image.fill(QColor("white").rgb())
        painter = QPainter(image)
        svg.render(painter)
        painter.end()
        array = QByteArray()
        buffer = QBuffer(array)
        buffer.open(QIODevice.WriteOnly)
        image.save(buffer, format)
        return str(array)
开发者ID:Hainish,项目名称:calibre,代码行数:44,代码来源:rasterize.py

示例15: rasterize_external

# 需要导入模块: from PyQt4.QtCore import QBuffer [as 别名]
# 或者: from PyQt4.QtCore.QBuffer import open [as 别名]
 def rasterize_external(self, elem, style, item, svgitem):
     width = style['width']
     height = style['height']
     width = (width / 72) * self.profile.dpi
     height = (height / 72) * self.profile.dpi
     data = QByteArray(str(svgitem))
     svg = QSvgRenderer(data)
     size = svg.defaultSize()
     size.scale(width, height, Qt.KeepAspectRatio)
     key = (svgitem.href, size.width(), size.height())
     if key in self.images:
         href = self.images[key]
     else:
         logger = self.oeb.logger
         logger.info('Rasterizing %r to %dx%d'
                     % (svgitem.href, size.width(), size.height()))
         image = QImage(size, QImage.Format_ARGB32_Premultiplied)
         image.fill(QColor("white").rgb())
         painter = QPainter(image)
         svg.render(painter)
         painter.end()
         array = QByteArray()
         buffer = QBuffer(array)
         buffer.open(QIODevice.WriteOnly)
         image.save(buffer, 'PNG')
         data = str(array)
         manifest = self.oeb.manifest
         href = os.path.splitext(svgitem.href)[0] + '.png'
         id, href = manifest.generate(svgitem.id, href)
         manifest.add(id, href, PNG_MIME, data=data)
         self.images[key] = href
     elem.tag = XHTML('img')
     for attr in elem.attrib:
         if attr not in KEEP_ATTRS:
             del elem.attrib[attr]
     elem.attrib['src'] = item.relhref(href)
     if elem.text:
         elem.attrib['alt'] = elem.text
         elem.text = None
     for child in elem:
         elem.remove(child)
开发者ID:089git,项目名称:calibre,代码行数:43,代码来源:rasterize.py


注:本文中的PyQt4.QtCore.QBuffer.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。