[英]changing pixel color with setPixel
I have ab/w picture I need to edit pixel by pixel. 我有ab / w图片我需要逐像素编辑。 If a pixel too dark it's color should be changed to black.
如果像素太暗,则应将其颜色更改为黑色。 Here's my code:
这是我的代码:
for i in range(width):
for j in range(height):
pixel_value = int(hex(self.img.pixel(i, j))[8:], 16)
if pixel_value < 110:
self.img.setPixel(i, j, .......)
So the problem is I don't know how to pass a color to setPixel(). 所以问题是我不知道如何将颜色传递给setPixel()。 AFAIK it should be something like
AFAIK应该是这样的
self.img.setPixel(i, j, qRgb(0, 0, 0))
I'm using PyQt5.12.3 and I don't know how to import qRgb. 我正在使用PyQt5.12.3,我不知道如何导入qRgb。 PyQt5.QtGui only has qRgba64.
PyQt5.QtGui只有qRgba64。 If qRgba64 is also ok for setPixel() then how do I pass black color with qRgba64?
如果qRgba64也适用于setPixel(),那么如何使用qRgba64传递黑色?
I find the problem that you point out strange because if there exists the class qRgb in PyQt5 5.12.3 (I have also tested it in PyQt5 5.13.0): 我发现你指出的问题很奇怪,因为如果在PyQt5 5.12.3中存在类qRgb(我也在PyQt5 5.13.0中测试过它):
image.setPixel(i, j, QtGui.qRgb(0, 0, 0))
But anyway, if you want to use setPixelColor() and convert the QRgba64 to QColor: 但无论如何,如果你想使用setPixelColor()并将QRgba64转换为QColor:
image.setPixelColor(i, j, QtGui.QColor(QtGui.QRgba64.fromRgba(0, 0, 0, 255)))
Or better to use QColor: 或者更好地使用QColor:
image.setPixelColor(i, j, QtGui.QColor(0, 0, 0))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.