本文整理匯總了Python中PyQt4.QtGui.QImage.Format_ARGB32方法的典型用法代碼示例。如果您正苦於以下問題:Python QImage.Format_ARGB32方法的具體用法?Python QImage.Format_ARGB32怎麽用?Python QImage.Format_ARGB32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt4.QtGui.QImage
的用法示例。
在下文中一共展示了QImage.Format_ARGB32方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save
# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.QtGui.QImage import Format_ARGB32 [as 別名]
def save(self, filePath, ch=None):
if filePath.hasExt('.r32'):
import struct
# heightfield export
pixels = self._width * self._height
buffer = (ctypes.c_float * pixels)()
glGetTexImage(GL_TEXTURE_2D, 0, GL_RED, GL_FLOAT, buffer)
with filePath.edit(flag='wb') as fh:
fh.write(struct.pack('%sf' % pixels, *buffer))
return
from PyQt4.QtGui import QImage
pixels = self._width * self._height
buffer = (ctypes.c_ubyte * (pixels * 4))()
mirror = (ctypes.c_ubyte * (pixels * 4))()
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer)
for i in xrange(0, pixels * 4, 4):
if ch is None:
mirror[i:i + 4] = (buffer[i + 2], buffer[i + 1], buffer[i], buffer[i + 3])
else:
mirror[i:i + 4] = (buffer[i + ch], buffer[i + ch], buffer[i + ch], 255)
QImage(mirror, self._width, self._height, QImage.Format_ARGB32).save(filePath)
示例2: combineTiles
# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.QtGui.QImage import Format_ARGB32 [as 別名]
def combineTiles(self):
global radar1
ii = QImage(self.tilesWidth*256, self.tilesHeight*256,
QImage.Format_ARGB32)
painter = QPainter()
painter.begin(ii)
painter.setPen(QColor(255, 255, 255, 255))
painter.setFont(QFont("Arial", 10))
i = 0
xo = self.cornerTiles["NW"]["X"]
xo = int((int(xo) - xo)*256)
yo = self.cornerTiles["NW"]["Y"]
yo = int((int(yo) - yo)*256)
for y in range(0, self.totalHeight, 256):
for x in range(0, self.totalWidth, 256):
if self.tileQimages[i].format() == 5:
painter.drawImage(x, y, self.tileQimages[i])
# painter.drawRect(x, y, 255, 255)
# painter.drawText(x+3, y+12, self.tiletails[i])
i += 1
painter.end()
painter = None
self.tileQimages = []
ii2 = ii.copy(-xo, -yo, self.rect.width(), self.rect.height())
ii = None
painter2 = QPainter()
painter2.begin(ii2)
timestamp = "{0:%H:%M} rainvewer.com".format(
datetime.datetime.fromtimestamp(self.getTime))
painter2.setPen(QColor(63, 63, 63, 255))
painter2.setFont(QFont("Arial", 8))
painter2.setRenderHint(QPainter.TextAntialiasing)
painter2.drawText(3-1, 12-1, timestamp)
painter2.drawText(3+2, 12+1, timestamp)
painter2.setPen(QColor(255, 255, 255, 255))
painter2.drawText(3, 12, timestamp)
painter2.drawText(3+1, 12, timestamp)
painter2.end()
painter2 = None
ii3 = QPixmap(ii2)
ii2 = None
self.frameImages.append({"time": self.getTime, "image": ii3})
ii3 = None
示例3: basefinished
# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.QtGui.QImage import Format_ARGB32 [as 別名]
def basefinished(self):
if self.basereply.error() != QNetworkReply.NoError:
return
self.basepixmap = QPixmap()
self.basepixmap.loadFromData(self.basereply.readAll())
if self.basepixmap.size() != self.rect.size():
self.basepixmap = self.basepixmap.scaled(self.rect.size(),
Qt.KeepAspectRatio,
Qt.SmoothTransformation)
self.setPixmap(self.basepixmap)
# make marker pixmap
self.mkpixmap = QPixmap(self.basepixmap.size())
self.mkpixmap.fill(Qt.transparent)
br = QBrush(QColor(Config.dimcolor))
painter = QPainter()
painter.begin(self.mkpixmap)
painter.fillRect(0, 0, self.mkpixmap.width(),
self.mkpixmap.height(), br)
for marker in self.radar['markers']:
if 'visible' not in marker or marker['visible'] == 1:
pt = getPoint(marker["location"], self.point, self.zoom,
self.rect.width(), self.rect.height())
mk2 = QImage()
mkfile = 'teardrop'
if 'image' in marker:
mkfile = marker['image']
if os.path.dirname(mkfile) == '':
mkfile = os.path.join('markers', mkfile)
if os.path.splitext(mkfile)[1] == '':
mkfile += '.png'
mk2.load(mkfile)
if mk2.format != QImage.Format_ARGB32:
mk2 = mk2.convertToFormat(QImage.Format_ARGB32)
mkh = 80 # self.rect.height() / 5
if 'size' in marker:
if marker['size'] == 'small':
mkh = 64
if marker['size'] == 'mid':
mkh = 70
if marker['size'] == 'tiny':
mkh = 40
if 'color' in marker:
c = QColor(marker['color'])
(cr, cg, cb, ca) = c.getRgbF()
for x in range(0, mk2.width()):
for y in range(0, mk2.height()):
(r, g, b, a) = QColor.fromRgba(
mk2.pixel(x, y)).getRgbF()
r = r * cr
g = g * cg
b = b * cb
mk2.setPixel(x, y, QColor.fromRgbF(r, g, b, a)
.rgba())
mk2 = mk2.scaledToHeight(mkh, 1)
painter.drawImage(pt.x-mkh/2, pt.y-mkh/2, mk2)
painter.end()
self.wmk.setPixmap(self.mkpixmap)
示例4: _toqclass_helper
# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.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
}
示例5: _toqclass_helper
# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.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
}
示例6: __init__
# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.QtGui.QImage import Format_ARGB32 [as 別名]
def __init__(self, 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 = unicode(im.toUtf8(), "utf-8")
if Image.isStringType(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.tostring("raw", "BGRX")
format = QImage.Format_RGB32
elif im.mode == "RGBA":
try:
data = im.tostring("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)
# must keep a reference, or Qt will crash!
self.__data = data or im.tostring()
QImage.__init__(self, self.__data, im.size[0], im.size[1], format)
if colortable:
self.setColorTable(colortable)
示例7: _toqclass_helper
# 需要導入模塊: from PyQt4.QtGui import QImage [as 別名]
# 或者: from PyQt4.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
}