In some interface using PyQt5
, let button
be a QPushButton. If we want to set an icon for the button using a given saved image image.jpg
, we usually write:
button.setIcon(QtGui.QIcon("image.jpg"))
However, if I am given an n-dimensional numpy array array
which also represents an image, I cannot simply write button.setIcon(QtGui.QIcon(array))
as it will give an error message. What should I do to instead? (saving the array as an image is not in consideration as I want large amount of arrays to be made into PushButton)
Edit:
For a typical situation, consider:
import numpy
array = numpy.random.rand(100,100,3) * 255
Then array
is a square array representing an image. To see this, we can write (we do not have to use PIL
or Image
to solve our problem and this is just a demonstration):
from PIL import Image
im = Image.fromarray(imarray.astype('uint8')).convert('RGBA')
Reference:100x100 image with random pixel colour
I want to make this fixed array an icon.