Answer the question
In order to leave comments, you need to log in
How to draw a pixelated image in Python?
Hello, I need a library, a framework or just an algorithm for drawing pixels with python, with the ability to scale an image...
For example:
There is a two-dimensional 4x4 array...
And in each "cell" there is a code (rgb, hex or other) that denotes color, and a "picture" is drawn on this array, which can be viewed ...
And it is also necessary that the array can change during the program and the same pattern, respectively ...
Answer the question
In order to leave comments, you need to log in
To start)
import sys
import numpy
from PIL import Image
from PIL.ImageQt import ImageQt
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QMessageBox
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtCore import Qt
def log_uncaught_exceptions(ex_cls, ex, tb):
text = '{}: {}:\n\n'.format(ex_cls.__name__, ex)
import traceback
text += ''.join(traceback.format_tb(tb))
QMessageBox.critical(None, 'Ошибка!', text)
quit()
sys.excepthook = log_uncaught_exceptions
class ShowImage(QMainWindow):
def __init__(self):
super().__init__()
self.interface()
def interface(self):
self.setWindowTitle("Пример рисования изображения")
self.setGeometry(400, 200, 600, 400)
pixel = numpy.zeros((10, 10, 3)).astype(int)
pixel[0][0][2] = 255
print(pixel)
image = Image.fromarray(pixel, 'RGB')
self.image_qt = ImageQt(image)
pixmap = QPixmap(QImage(self.image_qt))
label = QLabel(self)
label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
label.setStyleSheet("background-color: white")
label.setGeometry(0, 0, 100, 100)
label.setPixmap(pixmap)
if __name__ == "__main__":
app = QApplication(sys.argv)
my_application = ShowImage()
my_application.show()
sys.exit(app.exec_())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question