I want to view the original Image file.
But all Images are converted into the spotted,corrupted image.
It seems that the previous image is not equal to the behind image.
Please change the image size in the QImage's constructor into your arbitrary sample image's size.
If I excute this code, I caught the corrupted Image. Why?
I tried to change Format.Format_ARGB32_Premultiplied into various patterns.
But all patterns didn't go well.
from PIL import Image
import numpy as np
from PySide import QtCore
from PySide import QtGui
import sys
#the original file
filename = 'Any_Data.png'
im = Image.open(filename)
data = np.array(im)
file_ = QtCore.QFile("test_file.img")
file_.open(QtCore.QIODevice.WriteOnly)
qdatastream = QtCore.QDataStream(file_)
bytedatas = QtCore.QByteArray(data.tobytes())
#print(bytedatas)
#print(len(data.tobytes()),type(data))
qdatastream << bytedatas
output_file_ = QtCore.QFile("test_file.img")
output_file_.open(QtCore.QIODevice.ReadOnly)
qdatastream = QtCore.QDataStream(output_file_)
#the behind file
bytedata = QtCore.QByteArray()
qdatastream >> bytedata
Image = QtGui.QImage(220,133,QtGui.QImage.Format.Format_ARGB32_Premultiplied)
Image.fromData(bytedata)
def main():
try:
QtGui.QApplication([])
except Exception as e:
print(e)
widget = QtGui.QLabel()
pixmap = QtGui.QPixmap()
pixmap.convertFromImage(Image)
widget.setPixmap(pixmap)
widget.show()
sys.exit(QtGui.QApplication.exec_())
if __name__ == "__main__":
main()