本文整理汇总了Python中PyQt5.QtGui.QImage.Format_ARGB32方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.Format_ARGB32方法的具体用法?Python QImage.Format_ARGB32怎么用?Python QImage.Format_ARGB32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QImage
的用法示例。
在下文中一共展示了QImage.Format_ARGB32方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: array_to_qimage
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def array_to_qimage(im: np.ndarray, copy=False):
gray_color_table = [qRgb(i, i, i) for i in range(256)]
if im is None:
return QImage()
if im.dtype == np.uint8:
if len(im.shape) == 2:
qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_Indexed8)
qim.setColorTable(gray_color_table)
return qim.copy() if copy else qim
elif len(im.shape) == 3:
if im.shape[2] == 3:
qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_RGB888);
return qim.copy() if copy else qim
elif im.shape[2] == 4:
qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_ARGB32);
return qim.copy() if copy else qim
示例2: expandAndFormat
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def expandAndFormat(img, margin=0, is_jpg=False):
"""
Draws the image with transparent background if `is_jpg == False`, otherwise with a white background.
It's done in a single function, to avoid creating extra images
"""
if not margin and not is_jpg:
return img
corner = QSize(margin, margin)
white = QColor(255, 255, 255) if is_jpg else QColor(255, 255, 255, 0)
canvas = QImage(
img.size() + corner * 2, QImage.Format_RGB32 if is_jpg else QImage.Format_ARGB32
)
canvas.fill(white)
p = QPainter(canvas)
p.drawImage(margin, margin, img)
return canvas
示例3: create_font_array
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def create_font_array(self):
# Load the first image to get font size
img = QImage(os.path.join(settings.gfx_path, 'font/32.png'))
imgsize = (img.width(), img.height())
self.char_ar = float(imgsize[1]) / imgsize[0]
# Set-up the texture array
self.tex_id = gl.glGenTextures(1)
gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.tex_id)
gl.glTexImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA8, imgsize[0], imgsize[1], 127 - 30, 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, None)
gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER)
gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER)
# We're using the ASCII range 32-126; space, uppercase, lower case, numbers, brackets, punctuation marks
for i in range(30, 127):
img = QImage(os.path.join(settings.gfx_path, 'font/%d.png' % i)).convertToFormat(QImage.Format_ARGB32)
ptr = c_void_p(int(img.constBits()))
gl.glTexSubImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i - 30, imgsize[0], imgsize[1], 1, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, ptr)
示例4: create_font_array
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def create_font_array(self, path):
# Load the first image to get font size
img = QImage(path + '32.png')
imgsize = (img.width(), img.height())
self.char_ar = float(imgsize[1]) / imgsize[0]
# Set-up the texture array
self.tex_id = gl.glGenTextures(1)
gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.tex_id)
gl.glTexImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA8, imgsize[0], imgsize[1], 127 - 32, 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, None)
gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER)
gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER)
# We're using the ASCII range 32-126; space, uppercase, lower case, numbers, brackets, punctuation marks
for i in range(32, 127):
img = QImage(path + '%d.png' % i).convertToFormat(QImage.Format_ARGB32)
ptr = c_void_p(int(img.constBits()))
gl.glTexSubImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i - 32, imgsize[0], imgsize[1], 1, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, ptr)
示例5: load_lcd_font
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def load_lcd_font():
files = sorted(glob('mcp_font/*.png'))
img = QImage(files[0])
imgsize = (img.width(), img.height())
# Set-up the texture array
tex_id = gl.glGenTextures(1)
gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, tex_id)
gl.glTexImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA8, imgsize[0], imgsize[1], len(files), 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, None)
gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER)
gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER)
for i, fname in enumerate(files):
img = QImage(fname).convertToFormat(QImage.Format_ARGB32)
ptr = c_void_p(int(img.constBits()))
gl.glTexSubImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, imgsize[0], imgsize[1], 1, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, ptr)
return tex_id
示例6: create_image
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def create_image(data: np.ndarray, colormap, data_min=None, data_max=None, normalize=True) -> QImage:
"""
Create QImage from ARGB array.
The ARGB must have shape (width, height, 4) and dtype=ubyte.
NOTE: The order of values in the 3rd axis must be (blue, green, red, alpha).
:return:
"""
image_data = Spectrogram.apply_bgra_lookup(data, colormap, data_min, data_max, normalize)
if not image_data.flags['C_CONTIGUOUS']:
logger.debug("Array was not C_CONTIGUOUS. Converting it.")
image_data = np.ascontiguousarray(image_data)
try:
# QImage constructor needs inverted row/column order
image = QImage(image_data.ctypes.data, image_data.shape[1], image_data.shape[0], QImage.Format_ARGB32)
except Exception as e:
logger.error("could not create image " + str(e))
return QImage()
image.data = image_data
return image
示例7: np2Qt
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def np2Qt(image):
"""Convert numpy array to QPixmap.
"""
height, width, bytesPerComponent = image.shape
bytesPerLine = 4 * width
if bytesPerComponent == 3:
image = cv2.cvtColor(image, cv2.COLOR_RGB2RGBA)
qimg = QImage(image.data, width, height,
bytesPerLine, QImage.Format_ARGB32)
return QPixmap.fromImage(qimg)
示例8: _toqclass_helper
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def _toqclass_helper(im):
data = None
colortable = None
# handle filename, if given instead of image name
if hasattr(im, "toUtf8"):
# FIXME - is this really the best way to do this?
im = str(im.toUtf8(), "utf-8")
if isPath(im):
im = Image.open(im)
if im.mode == "1":
format = QImage.Format_Mono
elif im.mode == "L":
format = QImage.Format_Indexed8
colortable = []
for i in range(256):
colortable.append(rgb(i, i, i))
elif im.mode == "P":
format = QImage.Format_Indexed8
colortable = []
palette = im.getpalette()
for i in range(0, len(palette), 3):
colortable.append(rgb(*palette[i : i + 3]))
elif im.mode == "RGB":
data = im.tobytes("raw", "BGRX")
format = QImage.Format_RGB32
elif im.mode == "RGBA":
try:
data = im.tobytes("raw", "BGRA")
except SystemError:
# workaround for earlier versions
r, g, b, a = im.split()
im = Image.merge("RGBA", (b, g, r, a))
format = QImage.Format_ARGB32
else:
raise ValueError("unsupported image mode %r" % im.mode)
__data = data or align8to32(im.tobytes(), im.size[0], im.mode)
return {"data": __data, "im": im, "format": format, "colortable": colortable}
示例9: bind
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def bind(self, texture_unit):
"""Bind the texture to a certain texture unit.
:param texture_unit: The texture unit to bind to.
"""
if not self._qt_texture.isCreated():
if self._file_name != None:
self._image = QImage(self._file_name).mirrored()
elif self._image is None: # No filename or image set.
self._image = QImage(1, 1, QImage.Format_ARGB32)
self._image.fill(0)
self._qt_texture.setData(self._image)
self._qt_texture.setMinMagFilters(QOpenGLTexture.Linear, QOpenGLTexture.Linear)
self._qt_texture.bind(texture_unit)
示例10: nodeToImage
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def nodeToImage(wnode):
"""
Returns an QImage 8-bit sRGB
"""
SRGB_PROFILE = "sRGB-elle-V2-srgbtrc.icc"
if wnode.trim == False:
bounds = KI.activeDocument().bounds()
x = bounds.x()
y = bounds.y()
w = bounds.width()
h = bounds.height()
else:
[x, y, w, h] = wnode.bounds
is_srgb = (
wnode.node.colorModel() == "RGBA"
and wnode.node.colorDepth() == "U8"
and wnode.node.colorProfile().lower() == SRGB_PROFILE.lower()
)
if is_srgb:
pixel_data = wnode.node.projectionPixelData(x, y, w, h).data()
else:
temp_node = wnode.node.duplicate()
temp_node.setColorSpace("RGBA", "U8", SRGB_PROFILE)
pixel_data = temp_node.projectionPixelData(x, y, w, h).data()
return QImage(pixel_data, w, h, QImage.Format_ARGB32)
示例11: saveCOASpriteSheet
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def saveCOASpriteSheet(self, dirname=""):
"""
Generate a vertical sheet of equaly sized frames
Each child of self is pasted to a master sheet
"""
images = self.children
tiles_x, tiles_y = 1, len(images) # Length of vertical sheet
image_width, image_height = self.size # Target frame size
sheet_width, sheet_height = (image_width, image_height * tiles_y) # Sheet dimensions
sheet = QImage(sheet_width, sheet_height, QImage.Format_ARGB32)
sheet.fill(QColor(255, 255, 255, 0))
painter = QPainter(sheet)
p_coord_x, p_coord_y = self.position
for count, image in enumerate(images):
coord_x, coord_y = image.position
coord_rel_x, coord_rel_y = coord_x - p_coord_x, coord_y - p_coord_y
painter.drawImage(
coord_rel_x, image_height * count + coord_rel_y, nodeToImage(image),
)
meta = self.meta
path, extension = "", meta["e"]
dirPath = (
exportPath(self.cfg, path, dirname)
if path
else exportPath(self.cfg, pathFS(self.parent), dirname)
)
os.makedirs(dirPath, exist_ok=True)
path = "{}{}".format(os.path.join(dirPath, self.name), ".{e}")
path = path.format(e=extension[0])
is_jpg = extension in ("jpg", "jpeg")
if is_jpg:
sheet = expandAndFormat(sheet, is_jpg=True)
sheet.save(path, quality=90 if is_jpg else -1)
return path, {"tiles_x": tiles_x, "tiles_y": tiles_y}
示例12: _toqclass_helper
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def _toqclass_helper(im):
data = None
colortable = None
# handle filename, if given instead of image name
if hasattr(im, "toUtf8"):
# FIXME - is this really the best way to do this?
if py3:
im = str(im.toUtf8(), "utf-8")
else:
im = unicode(im.toUtf8(), "utf-8")
if isPath(im):
im = Image.open(im)
if im.mode == "1":
format = QImage.Format_Mono
elif im.mode == "L":
format = QImage.Format_Indexed8
colortable = []
for i in range(256):
colortable.append(rgb(i, i, i))
elif im.mode == "P":
format = QImage.Format_Indexed8
colortable = []
palette = im.getpalette()
for i in range(0, len(palette), 3):
colortable.append(rgb(*palette[i:i+3]))
elif im.mode == "RGB":
data = im.tobytes("raw", "BGRX")
format = QImage.Format_RGB32
elif im.mode == "RGBA":
try:
data = im.tobytes("raw", "BGRA")
except SystemError:
# workaround for earlier versions
r, g, b, a = im.split()
im = Image.merge("RGBA", (b, g, r, a))
format = QImage.Format_ARGB32
else:
raise ValueError("unsupported image mode %r" % im.mode)
__data = data or align8to32(im.tobytes(), im.size[0], im.mode)
return {
'data': __data, 'im': im, 'format': format, 'colortable': colortable
}
示例13: _toqclass_helper
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def _toqclass_helper(im):
data = None
colortable = None
# handle filename, if given instead of image name
if hasattr(im, "toUtf8"):
# FIXME - is this really the best way to do this?
if py3:
im = str(im.toUtf8(), "utf-8")
else:
im = unicode(im.toUtf8(), "utf-8") # noqa: F821
if isPath(im):
im = Image.open(im)
if im.mode == "1":
format = QImage.Format_Mono
elif im.mode == "L":
format = QImage.Format_Indexed8
colortable = []
for i in range(256):
colortable.append(rgb(i, i, i))
elif im.mode == "P":
format = QImage.Format_Indexed8
colortable = []
palette = im.getpalette()
for i in range(0, len(palette), 3):
colortable.append(rgb(*palette[i:i+3]))
elif im.mode == "RGB":
data = im.tobytes("raw", "BGRX")
format = QImage.Format_RGB32
elif im.mode == "RGBA":
try:
data = im.tobytes("raw", "BGRA")
except SystemError:
# workaround for earlier versions
r, g, b, a = im.split()
im = Image.merge("RGBA", (b, g, r, a))
format = QImage.Format_ARGB32
else:
raise ValueError("unsupported image mode %r" % im.mode)
__data = data or align8to32(im.tobytes(), im.size[0], im.mode)
return {
'data': __data, 'im': im, 'format': format, 'colortable': colortable
}
示例14: _toqclass_helper
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_ARGB32 [as 别名]
def _toqclass_helper(im):
data = None
colortable = None
# handle filename, if given instead of image name
if hasattr(im, "toUtf8"):
# FIXME - is this really the best way to do this?
if str is bytes:
im = unicode(im.toUtf8(), "utf-8")
else:
im = str(im.toUtf8(), "utf-8")
if isPath(im):
im = Image.open(im)
if im.mode == "1":
format = QImage.Format_Mono
elif im.mode == "L":
format = QImage.Format_Indexed8
colortable = []
for i in range(256):
colortable.append(rgb(i, i, i))
elif im.mode == "P":
format = QImage.Format_Indexed8
colortable = []
palette = im.getpalette()
for i in range(0, len(palette), 3):
colortable.append(rgb(*palette[i:i+3]))
elif im.mode == "RGB":
data = im.tobytes("raw", "BGRX")
format = QImage.Format_RGB32
elif im.mode == "RGBA":
try:
data = im.tobytes("raw", "BGRA")
except SystemError:
# workaround for earlier versions
r, g, b, a = im.split()
im = Image.merge("RGBA", (b, g, r, a))
format = QImage.Format_ARGB32
else:
raise ValueError("unsupported image mode %r" % im.mode)
__data = data or align8to32(im.tobytes(), im.size[0], im.mode)
return {
'data': __data, 'im': im, 'format': format, 'colortable': colortable
}