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


Python QPixmap.fromImage方法代码示例

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


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

示例1: convert_bitmap

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
def convert_bitmap(image, width=None, height=None):
    pix = None
    if isinstance(image, ImageResource):
        pix = traitsui_convert_bitmap(image)
    elif isinstance(image, Image):
        # image = image.convert('RGBA')
        data = image.tostring('raw', 'RGBA')
        im = QImage(data, image.size[0], image.size[1], QImage.Format_ARGB32)
        pix = QPixmap.fromImage(QImage.rgbSwapped(im))
    else:
        s = image.shape
        if len(s) >= 2:
            # im = QImage(image.tostring(),s[1], s[0], QImage.Format_RGB888)
            im = QImage(image, s[1], s[0], QImage.Format_RGB888)
            pix = QPixmap.fromImage(QImage.rgbSwapped(im))
        else:
            pix = QPixmap()
    if pix:
        if width > 0 and height > 0:
            pix = pix.scaled(width, height)
        elif width > 0:
            pix = pix.scaledToWidth(width)
        if height > 0:
            pix = pix.scaledToHeight(height)

    return pix
开发者ID:OSUPychron,项目名称:pychron,代码行数:28,代码来源:image_editor.py

示例2: _wait_for_frame

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
 def _wait_for_frame(self):
     if self.camera.wait_for_frame(0):
         data = self.camera.image_buffer()
         bpl = self.camera.bytes_per_line
         format = QImage.Format_RGB32
         image = QImage(data, self.camera.width, self.camera.height, bpl, format)
         if self.pixmapitem is None:
             self.pixmapitem = self.scene.addPixmap(QPixmap.fromImage(image))
         else:
             self.pixmapitem.setPixmap(QPixmap.fromImage(image))
开发者ID:steveo3221,项目名称:Instrumental,代码行数:12,代码来源:gui.py

示例3: drawIconWithShadow

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
    def drawIconWithShadow(icon, rect, p, iconMode, radius, color, offset):
        cache = QPixmap()
        pixmapName = "icon {0} {1} {2}".format(icon.cacheKey(), iconMode, rect.height())

        if not QPixmapCache.find(pixmapName, cache):
            px = icon.pixmap(rect.size())
            cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
            cache.fill(Qt.transparent)

            cachePainter = QPainter(cache)
            if iconMode == QIcon.Disabled:
                im = px.toImage().convertToFormat(QImage.Format_ARGB32)
                for y in range(im.height()):
                    scanLine = im.scanLine(y)
                    for x in range(im.width()):
                        pixel = scanLine
                        intensity = qGray(pixel)
                        scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel))
                        scanLine += 1
                px = QPixmap.fromImage(im)

            # Draw shadow
            tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1), QImage.Format_ARGB32_Premultiplied)
            tmp.fill(Qt.transparent)

            tmpPainter = QPainter(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
            tmpPainter.drawPixmap(QPoint(radius, radius), px)
            tmpPainter.end()

            # blur the alpha channel
            blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
            blurred.fill(Qt.transparent)
            blurPainter = QPainter(blurred)
            # todo : blur image
            blurPainter.end()

            tmp = blurred

            # blacken the image
            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            # draw the blurred drop shadow...
            cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp)

            # Draw the actual pixmap...
            cachePainter.drawPixmap(QPoint(radius, radius) + offset, px)
            QPixmapCache.insert(pixmapName, cache)

        targetRect = cache.rect()
        targetRect.moveCenter(rect.center())
        p.drawPixmap(targetRect.topLeft() - offset, cache)
开发者ID:nichollyn,项目名称:libspark,代码行数:62,代码来源:stylehelper.py

示例4: pixmap_from_hicon

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
def pixmap_from_hicon(hicon):
    if not hicon: return
    screen_device = GetDC(None)
    hdc = CreateCompatibleDC(screen_device)
    ReleaseDC(None, screen_device)
    icon_info = ICONINFO()
    if not GetIconInfo(hicon, byref(icon_info)):
        raise WindowsError('call to GetIconInfo failed')
    width = icon_info.xHotspot * 2
    height = icon_info.yHotspot * 2
    bitmap_header = BITMAPINFOHEADER()
    bitmap_header.biSize = sizeof(bitmap_header)
    bitmap_header.biWidth = width
    bitmap_header.biHeight = height
    bitmap_header.biPlanes = 1
    bitmap_header.biBitCount = 32
    bitmap_header.biCompression = BI_RGB
    bitmap_header.biSizeImage = 0
    bitmap_header.biXPelsPerMeter = 0
    bitmap_header.biYPelsPerMeter = 0
    bitmap_header.biClrUsed = 0
    bitmap_header.biClrImportant = 0
    bits = c_void_p()
    win_bitmap = CreateDIBSection(hdc, byref(bitmap_header), DIB_RGB_COLORS, 
        byref(bits), None, 0);
    old_hdc = SelectObject(hdc, win_bitmap)
    DrawIconEx(hdc, 0, 0, hicon, width, height, 0, None, DI_NORMAL)
    image = image_from_hbitmap(hdc, win_bitmap, width, height)
    # do the alpha shit
    DeleteObject(icon_info.hbmMask)
    DeleteObject(icon_info.hbmColor)
    SelectObject(hdc, old_hdc)
    DeleteObject(win_bitmap)
    DeleteDC(hdc)
    return QPixmap.fromImage(image)
开发者ID:vstojkovic,项目名称:berk,代码行数:37,代码来源:win32_icon_provider.py

示例5: _set_pixmap_from_array

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
    def _set_pixmap_from_array(self, arr):
        bpl = arr.strides[0]
        is_rgb = len(arr.shape) == 3

        if is_rgb and arr.dtype == np.uint8:
            format = QImage.Format_RGB32
            image = QImage(arr.data, self.camera.width, self.camera.height, bpl, format)
        elif not is_rgb and arr.dtype == np.uint8:
            # TODO: Somehow need to make sure data is ordered as I'm assuming
            format = QImage.Format_Indexed8
            image = QImage(arr.data, self.camera.width, self.camera.height, bpl, format)
            self._saved_img = arr
        elif not is_rgb and arr.dtype == np.uint16:
            if not self._cmax:
                self._cmax = arr.max()  # Set cmax once from first image
            arr = scipy.misc.bytescale(arr, self._cmin, self._cmax)
            format = QImage.Format_Indexed8
            w, h = self.camera.width, self.camera.height
            image = QImage(arr.data, w, h, w, format)
            self._saved_img = arr  # Save a reference to keep Qt from crashing
        else:
            raise Exception("Unsupported color mode")

        self.setPixmap(QPixmap.fromImage(image))
        pixmap_size = self.pixmap().size()
        if pixmap_size != self.size():
            self.setMinimumSize(self.pixmap().size())
开发者ID:ZachGlassman,项目名称:Instrumental,代码行数:29,代码来源:gui.py

示例6: _set_pixmap_from_camera

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
    def _set_pixmap_from_camera(self):
        bpl = self.camera.bytes_per_line
        arr = self.camera.image_array()

        if self.camera.color_mode == 'RGB32':
            buf = self.camera.image_buffer()  # TODO: Fix to use image_array() instead
            format = QImage.Format_RGB32
            image = QImage(buf, self.camera.width, self.camera.height, bpl, format)
        elif self.camera.color_mode == 'mono8':
            # TODO: Somehow need to make sure data is ordered as I'm assuming
            format = QImage.Format_Indexed8
            image = QImage(arr.data, self.camera.width, self.camera.height, bpl, format)
            self._saved_img = arr
        elif self.camera.color_mode == 'mono16':
            pil_img = scipy.misc.toimage(arr)  # Normalize values to fit in uint8
            format = QImage.Format_Indexed8
            data = pil_img.tostring()
            image = QImage(data, pil_img.size[0], pil_img.size[1], pil_img.size[0], format)
            self._saved_img = data  # Save a reference to keep Qt from crashing
        elif self.camera.color_mode==None:
            buf = self.camera.image_buffer()  # TODO: Fix to use image_array() instead
            format = QImage.Format_RGB32
            image = QImage(buf, self.camera.width, self.camera.height, bpl, format)
        else:
            raise Exception("Unsupported color mode '{}'".format(self.camera.color_mode))

        self.setPixmap(QPixmap.fromImage(image))
        pixmap_size = self.pixmap().size()
        if pixmap_size != self.size():
            self.setMinimumSize(self.pixmap().size())
开发者ID:mv20100,项目名称:phd_code_activation,代码行数:32,代码来源:cameraView.py

示例7: mouseMoveEvent

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
 def mouseMoveEvent(self, e):
     """Creates a QDrag object with a LabelTextMime containing this
        label's text.
     """
     drag = QDrag(self)
     drag.setMimeData(LabelTextMime(self.text))
     drag.setPixmap(QPixmap.fromImage(self.createPixmap()))
     dropAction = drag.start(Qt.MoveAction)
开发者ID:LLNL,项目名称:boxfish,代码行数:10,代码来源:GUIUtils.py

示例8: sendMediaVideoFile

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
	def sendMediaVideoFile(self,jid,video,image):
		self._d("creating VIDEO MMS for " +jid + " - file: " + video)
		fmsg = WAXMPP.message_store.createMessage(jid);

		if image == "NOPREVIEW":
			m = hashlib.md5()
			url = QtCore.QUrl(video).toEncoded()
			m.update(url)
			image = WAConstants.THUMBS_PATH + "/screen/" + m.hexdigest() + ".jpeg"
		else:
			image = image.replace("file://","")

		user_img = QImage(image)
		if user_img.height() > user_img.width():
			preimg = QPixmap.fromImage(QImage(user_img.scaledToWidth(64, Qt.SmoothTransformation)))
		elif user_img.height() < user_img.width():
			preimg = QPixmap.fromImage(QImage(user_img.scaledToHeight(64, Qt.SmoothTransformation)))
		else:
			preimg = QPixmap.fromImage(QImage(user_img.scaled(64, 64, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)))
		preimg.save(WAConstants.CACHE_PATH+"/temp2.png", "PNG")

		f = open(WAConstants.CACHE_PATH+"/temp2.png", 'r')
		stream = base64.b64encode(f.read())
		f.close()

		mediaItem = WAXMPP.message_store.store.Media.create()
		mediaItem.mediatype_id = 4
		mediaItem.local_path = video.replace("file://","")
		mediaItem.transfer_status = 0
		mediaItem.preview = stream
		
		try:
			mediaItem.size = os.path.getsize(mediaItem.local_path)
		except:
			pass

		fmsg.content = QtCore.QCoreApplication.translate("WAEventHandler", "Video")
		fmsg.Media = mediaItem

		if fmsg.Conversation.type == "group":
			contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(self.conn.jid)
			fmsg.setContact(contact);
		
		fmsg.setData({"status":0,"content":fmsg.content,"type":1})
		WAXMPP.message_store.pushMessage(jid,fmsg)
开发者ID:timofonic,项目名称:wazapp,代码行数:47,代码来源:waxmpp.py

示例9: colorbarChange

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
 def colorbarChange(self, ind):
     """Handles a selection of a different colormap."""
     indx = self.mapCombo.currentIndex()
     self.color_map_name = map_names[indx]
     self.color_map = getMap(self.color_map_name)
     self.colorbar.setPixmap(QPixmap.fromImage(ColorBarImage(
         self.color_map, 180, 12)))
     self.changeSignal.emit(ColorMap(self.color_map_name, self.color_step,
         self.step_size), self.tag)
开发者ID:Schizo,项目名称:boxfish,代码行数:11,代码来源:ColorMaps.py

示例10: __webcam

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
    def __webcam(self):
	capture = cv.CaptureFromCAM(-1)	
	for i in range(10):
		frame = cv.QueryFrame(capture)
	if not frame:
		return
	arr = self.__cv2array(frame)
	image = self.__toQImage(arr)
	image = image.rgbSwapped()
	self.__ui.photo_label.setPixmap(QPixmap.fromImage(image).scaled(self.__ui.photo_label.size(),Qt.KeepAspectRatio))
开发者ID:katcipis,项目名称:smartbuilding.accesscontrol,代码行数:12,代码来源:register_dialog.py

示例11: _set_image

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
    def _set_image(self, color1, color2):
        xpm = ['17 17 3 1',  # width height ncolors chars_per_pixel
               '0 c None',
               'X c {}'.format(color1.name()),
               '- c {}'.format(color2.name())
               ]
        xpm += [s.strip() for s in self.ascii_led.splitlines()]

        qim = QImage(xpm)
        pix = QPixmap.fromImage(qim)
        self.setPixmap(pix)
开发者ID:softtrainee,项目名称:arlab,代码行数:13,代码来源:led_editor.py

示例12: __init__

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
 def __init__(self, parent=None):
     self.hamburger = QImage(128, 128, QImage.Format_ARGB32)
     QPushButton.__init__(self, parent)
     self.svgrenderer = QSvgRenderer("icons\\hamburger.svg")
     paint = QPainter(self.hamburger)
     paint.setRenderHint(QPainter.HighQualityAntialiasing)
     paint.setRenderHint(QPainter.SmoothPixmapTransform)
     self.svgrenderer.render(paint)
     paint.end()
     pixmap = QPixmap()
     self.setIcon(QIcon(pixmap.fromImage(self.hamburger)))
     self.setStyleSheet("QPushButton, QPushButton:pressed{background-color: rgba(0,0,0,0)} QPushButton:hover {background-color: rgba(255,255,255,100); border-radius: 32px} ")
开发者ID:ethanhs,项目名称:material,代码行数:14,代码来源:material.py

示例13: sendMediaImageFile

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
	def sendMediaImageFile(self,jid,image):
		image = image.replace("file://","")

		user_img = QImage(image)

		if user_img.height() > user_img.width():
			preimg = QPixmap.fromImage(QImage(user_img.scaledToWidth(64, Qt.SmoothTransformation)))
		elif user_img.height() < user_img.width():
			preimg = QPixmap.fromImage(QImage(user_img.scaledToHeight(64, Qt.SmoothTransformation)))
		else:
			preimg = QPixmap.fromImage(QImage(user_img.scaled(64, 64, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)))

		preimg.save(WAConstants.CACHE_PATH+"/temp2.png", "PNG")
		f = open(WAConstants.CACHE_PATH+"/temp2.png", 'r')
		stream = base64.b64encode(f.read())
		f.close()

		self._d("creating PICTURE MMS for " +jid + " - file: " + image)
		fmsg = WAXMPP.message_store.createMessage(jid);
		
		mediaItem = WAXMPP.message_store.store.Media.create()
		mediaItem.mediatype_id = 2
		mediaItem.local_path = image
		mediaItem.transfer_status = 0
		mediaItem.preview = stream
		try:
			mediaItem.size = os.path.getsize(mediaItem.local_path)
		except:
			pass

		fmsg.content = QtCore.QCoreApplication.translate("WAEventHandler", "Image")
		fmsg.Media = mediaItem

		if fmsg.Conversation.type == "group":
			contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(self.conn.jid)
			fmsg.setContact(contact);
		
		fmsg.setData({"status":0,"content":fmsg.content,"type":1})
		WAXMPP.message_store.pushMessage(jid,fmsg)
开发者ID:timofonic,项目名称:wazapp,代码行数:41,代码来源:waxmpp.py

示例14: CheckBox

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
class CheckBox(QCheckBox):
    def __init__(self, *args):
        super(CheckBox, self).__init__(*args)
        self.setMouseTracking(True)
        if tuple() in [type(i) for i in args]:
            for arg in args:
                if isinstance(arg) == tuple():
                    color = arg
        else:
            color = (QColor(0, 150, 136), QColor(255, 255, 255))
        self.color1 = color[0]
        self.color2 = color[1]
        self.svgrenderer = QSvgRenderer("icons\\check.svg")

        self.check = QImage(500, 200, QImage.Format_ARGB32)
        self.resize(30, 30)
        paint = QPainter(self.check)
        self.svgrenderer.render(paint)
        paint.end()

    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        self.img = QPixmap()
        if self.isChecked():
            painter.setBrush(self.color1)
            painter.drawRoundedRect(QRect(-1, -1, 31, 31), 7, 7)
            painter.drawPixmap(QRect(-2, -5, 35, 40), self.img.fromImage(self.check))
        else:
            pen = QPen()
            pen.setWidth(2)
            painter.setPen(pen)
            # hand draw rect
            painter.drawLine(QPoint(0, 0), QPoint(30, 0))
            painter.drawLine(QPoint(30, 0), QPoint(30, 30))
            painter.drawLine(QPoint(0, 0), QPoint(0, 30))
            painter.drawLine(QPoint(0, 30), QPoint(30, 30))
        painter.end()

    def mouseReleaseEvent(self, event):
        if event.button() == Qt.LeftButton:
            if self.isChecked():

                self.setChecked(False)
            else:
                self.setChecked(True)
            self.repaint()
开发者ID:ethanhs,项目名称:material,代码行数:52,代码来源:material.py

示例15: set_yuv_image

# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import fromImage [as 别名]
    def set_yuv_image(self, img):
        """ Sets the spatial image as YUV array.

        The function expects a `uint8` array and will set the spatial domain
        image in the UI along with updating all internal fields.
        """

        self.spatial_image = img
        img = util.yuv_to_rgb(self.spatial_image)
        qimage = util.numpy_to_qimage(img)
        pixmap = QPixmap.fromImage(qimage)
        self.set_image_pixmap(pixmap)
        self.invalidate_image_scale()
        self.render_image()
开发者ID:fredo-editor,项目名称:FreDo,代码行数:16,代码来源:main.py


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