Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QImage into QByteArray - Can anyone tell me if what it has created is valid enough to be turned back into a PNG?
Forum Update on Monday, May 27th 2025

QImage into QByteArray - Can anyone tell me if what it has created is valid enough to be turned back into a PNG?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 194 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rsison
    wrote on last edited by
    #1

    I converted an image file into a bytearray via QTCreator's QBuffer, but I'm unsure if it's actually valid or not. I have been unable to find a place that lets me easily check if it is valid or not.

    "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x01\x19\x00\x00\x01-\b\x06\x00\x00\x00<\xFB\x14\xAC\x00\x00\x00\tpHYs\x00\x00\x0E\xC4\x00\x00\x0E\xC4\x01\x95+\x0E\x1B\x00\x00\x04+IDATx\x9C\xED\xD8\xB1M\xECP\x14""E\xD1\xF7\xBE(dh\x0F\xEA\x19\xB7\x07\x9D\\\x92\x8F c\x92-c\xB4\x96""d\xC9\xE1\x89\xB6\xAE\xBDgf\x16@\xE4\xDF\xD9\x03\x80\xBFMd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\xC3\xCF\x8E\xBD\xF6\xFEz\x8E\xB3\xF7p){f\xE6\xEC\x11\\\xC9\xF3\xDA\xCFok\xDE\xCE\xDE\xC1U\xB8""dx\xC0\xF1\xED\x92y_\xEB\xDD-\xC3\xE3""D\x86\x1F\x1Ck\xEF\xD7u\x9FY3\xB3""f\xEEg\x0F\xE2""bD\x86\x07\xDC\xD7\xCB\xE7\xEB\xF1z\xE6\x10.\xE8\xE9\xEC\x01\xFCv/kn{\xED\xFD?.\xB7\xDB\xA9k\xB8\x1E?~\x81\x94\xCF% %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 \xF5\x01\xFF%\"\xD5\x12\x0B\xB7\x80\x00\x00\x00\x00IEND\xAE""B`\x82\x00\x00IEND\xAE""B`\x82""d\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 \xF5\x17Y!-\x17\x9B\xE1o\xE0\x00\x00\x00\x00IEND\xAE""B`\x82"
    

    My original goal is to send an image from QTCreator to my python server via a datagram and turning it back into an image to be displayed. io.BytesIO doesn't seem to be recognizing the datagram as such, but even then what it's receiving is mildly different from the QTCreator console output. To me it seems to be skipping any event of x00 for some reason.

    bytearray(b'\x89PNG\r\n\x1a\n\xac\xc4\x01\x95+\x0e\x1b\xed\xd8\xb1M\xecP\x14E\xd1\xf7\xbe(dh\x0f\xea\x19\xb7\x07\x9d\\\x92\x8f c\x92-c\xb4\x96d\xc9\xe1\x89\xb6\xae\xbdgf\x16@\xe4\xdf\xd9\x03\x80\xbfMd\x80\x94\xc8\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8)\x91\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x19 %2@Jd\x80\x94\xc8\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x90\x12\x19 %2@Jd\x80\x94\xc8R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x91\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8 %2@Jd\x80\x94\xc8\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x12\x19 %2@Jd\x80\x94\xc8"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\xf6\xfez\x8e\xb3\xf7p){f\xe6\xec\x11\\\xc9\xf3\xda\xcfok\xde\xce\xde\xc1U\xb8dx\xc0\xf1\xed\x92y_\xeb\xdd-\xc3\xe3D\x86\x1f\x1ck\xef\xd7u\x9fY3\xb3f\xeeg\x0f\xe2bD\x86\x07\xdc\xd7\xcb\xe7\xeb\xf1z\xe6\x10.\xe8\xe9\xec\x01\xfcv/kn{\xed\xfd?.\xb7\xdb\xa9k\xb8\x1e?~\x81\x94\xcf% %2@Jd\x80\x94\xc8\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x12\x19 %2@Jd\x80\x94\xc8"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8)\x91\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x19 %2@Jd\x80\x94\xc8\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x90\x12\x19 %2@Jd\x80\x94\xc8R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x91\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8 %2@Jd\x80\x94\xc8\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x12\x19 \xf5\x01\xff%"\xd5\x12\x0b\xb7\x80B`\x82d\x80\x94\xc8\x06H\x89\x0c\x90\x12\x19 \xf5\x17Y!-\x17\x9b\xe1o\xe0')
    

    io.BytesIO itself it throwing this error, thus prompting me to wonder what is going wrong.

    PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001B63C862570>
    

    I'm stumped and unsure how to proceed.

    JonBJ 1 Reply Last reply
    0
    • R rsison

      I converted an image file into a bytearray via QTCreator's QBuffer, but I'm unsure if it's actually valid or not. I have been unable to find a place that lets me easily check if it is valid or not.

      "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x01\x19\x00\x00\x01-\b\x06\x00\x00\x00<\xFB\x14\xAC\x00\x00\x00\tpHYs\x00\x00\x0E\xC4\x00\x00\x0E\xC4\x01\x95+\x0E\x1B\x00\x00\x04+IDATx\x9C\xED\xD8\xB1M\xECP\x14""E\xD1\xF7\xBE(dh\x0F\xEA\x19\xB7\x07\x9D\\\x92\x8F c\x92-c\xB4\x96""d\xC9\xE1\x89\xB6\xAE\xBDgf\x16@\xE4\xDF\xD9\x03\x80\xBFMd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\xC3\xCF\x8E\xBD\xF6\xFEz\x8E\xB3\xF7p){f\xE6\xEC\x11\\\xC9\xF3\xDA\xCFok\xDE\xCE\xDE\xC1U\xB8""dx\xC0\xF1\xED\x92y_\xEB\xDD-\xC3\xE3""D\x86\x1F\x1Ck\xEF\xD7u\x9FY3\xB3""f\xEEg\x0F\xE2""bD\x86\x07\xDC\xD7\xCB\xE7\xEB\xF1z\xE6\x10.\xE8\xE9\xEC\x01\xFCv/kn{\xED\xFD?.\xB7\xDB\xA9k\xB8\x1E?~\x81\x94\xCF% %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 \xF5\x01\xFF%\"\xD5\x12\x0B\xB7\x80\x00\x00\x00\x00IEND\xAE""B`\x82\x00\x00IEND\xAE""B`\x82""d\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 \xF5\x17Y!-\x17\x9B\xE1o\xE0\x00\x00\x00\x00IEND\xAE""B`\x82"
      

      My original goal is to send an image from QTCreator to my python server via a datagram and turning it back into an image to be displayed. io.BytesIO doesn't seem to be recognizing the datagram as such, but even then what it's receiving is mildly different from the QTCreator console output. To me it seems to be skipping any event of x00 for some reason.

      bytearray(b'\x89PNG\r\n\x1a\n\xac\xc4\x01\x95+\x0e\x1b\xed\xd8\xb1M\xecP\x14E\xd1\xf7\xbe(dh\x0f\xea\x19\xb7\x07\x9d\\\x92\x8f c\x92-c\xb4\x96d\xc9\xe1\x89\xb6\xae\xbdgf\x16@\xe4\xdf\xd9\x03\x80\xbfMd\x80\x94\xc8\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8)\x91\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x19 %2@Jd\x80\x94\xc8\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x90\x12\x19 %2@Jd\x80\x94\xc8R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x91\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8 %2@Jd\x80\x94\xc8\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x12\x19 %2@Jd\x80\x94\xc8"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\xf6\xfez\x8e\xb3\xf7p){f\xe6\xec\x11\\\xc9\xf3\xda\xcfok\xde\xce\xde\xc1U\xb8dx\xc0\xf1\xed\x92y_\xeb\xdd-\xc3\xe3D\x86\x1f\x1ck\xef\xd7u\x9fY3\xb3f\xeeg\x0f\xe2bD\x86\x07\xdc\xd7\xcb\xe7\xeb\xf1z\xe6\x10.\xe8\xe9\xec\x01\xfcv/kn{\xed\xfd?.\xb7\xdb\xa9k\xb8\x1e?~\x81\x94\xcf% %2@Jd\x80\x94\xc8\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x12\x19 %2@Jd\x80\x94\xc8"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8)\x91\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x19 %2@Jd\x80\x94\xc8\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x90\x12\x19 %2@Jd\x80\x94\xc8R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x91\x01R"\x03\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8 %2@Jd\x80\x94\xc8\xa4D\x06H\x89\x0c\x90\x12\x19 %2@Jd\x80\x94\xc8\x12\x19 \xf5\x01\xff%"\xd5\x12\x0b\xb7\x80B`\x82d\x80\x94\xc8\x06H\x89\x0c\x90\x12\x19 \xf5\x17Y!-\x17\x9b\xe1o\xe0')
      

      io.BytesIO itself it throwing this error, thus prompting me to wonder what is going wrong.

      PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001B63C862570>
      

      I'm stumped and unsure how to proceed.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @rsison
      Check that length of image file at sender == number of bytes sent == number of bytes received == length of image used at receiver. Try saving bytes to file at receiver side and see whether you end up with identical to original file. If bytes of 0x00 are missing look at each stage to see what calls you are using.

      R 1 Reply Last reply
      1
      • JonBJ JonB

        @rsison
        Check that length of image file at sender == number of bytes sent == number of bytes received == length of image used at receiver. Try saving bytes to file at receiver side and see whether you end up with identical to original file. If bytes of 0x00 are missing look at each stage to see what calls you are using.

        R Offline
        R Offline
        rsison
        wrote on last edited by rsison
        #3

        @JonB I am receiving a total length of 791 from my chunked UDP datagrams, instead of 1198 total - please advise.
        I am unsure what calls would be skipping over 0x00.
        I am pre-checking the chunked output in QT Creator with qInfo << theByteArray.mid(section1,section2).

        "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR"
        "\x00\x00\x01\x19\x00\x00\x01-\b\x06\x00\x00\x00<\xFB\x14"
        "\xAC\x00\x00\x00\tpHYs\x00\x00\x0E\xC4\x00\x00\x0E"
        "\xC4\x01\x95+\x0E\x1B\x00\x00\x04""5IDATx\x9C"
        "\xED\xD8\xC1I\x03Q\x18""F\xD1\xF7\xC4""f\xEC\"\xB6\xE3"
        ".)$\xD9Y\x8B;\xBB\xD0r\x9E\x0B\x91\b\x82q"
        "s\x19""F\xCE\x81\xC0\fd\xF1\xAD.\xFC""3\xD7Zk"
        "\x00""D\xEE\xB6\x1E\x00\xFCo\"\x03\xA4""D\x06H\x89\f"
        "\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01"
        "R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@"
        "Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H"
        "\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)"
        "\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %"
        "2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D"
        "\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8"
        "\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19" // and even more
        

        I believe it might have something to do with the way I am chunking the bytearray? But QT Creator is showing each part as it is from the original array without any events of x00 missing.

        QByteArray s3 = s1;
            int chunkSize = 16;
            int chunkStart = 0;
            int tempSize = s3.size();
            qInfo() << "BREAK BASE";
            while (tempSize > 0){
                QByteArray Temp = s3.mid(chunkStart, chunkSize);
                qInfo() << Temp;
                tempSize = tempSize - chunkSize;
                chunkStart += chunkSize;
                socket.writeDatagram(Temp.data(), QHostAddress("127.0.0.1"), 80); // fill QHostAddress with the board's ethernet address
        

        Maybe I should attempt to use the TCP functions instead...? My previous assignments were done in UDP with much smaller payloads.

        B 1 Reply Last reply
        0
        • R rsison

          @JonB I am receiving a total length of 791 from my chunked UDP datagrams, instead of 1198 total - please advise.
          I am unsure what calls would be skipping over 0x00.
          I am pre-checking the chunked output in QT Creator with qInfo << theByteArray.mid(section1,section2).

          "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR"
          "\x00\x00\x01\x19\x00\x00\x01-\b\x06\x00\x00\x00<\xFB\x14"
          "\xAC\x00\x00\x00\tpHYs\x00\x00\x0E\xC4\x00\x00\x0E"
          "\xC4\x01\x95+\x0E\x1B\x00\x00\x04""5IDATx\x9C"
          "\xED\xD8\xC1I\x03Q\x18""F\xD1\xF7\xC4""f\xEC\"\xB6\xE3"
          ".)$\xD9Y\x8B;\xBB\xD0r\x9E\x0B\x91\b\x82q"
          "s\x19""F\xCE\x81\xC0\fd\xF1\xAD.\xFC""3\xD7Zk"
          "\x00""D\xEE\xB6\x1E\x00\xFCo\"\x03\xA4""D\x06H\x89\f"
          "\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)\x91\x01"
          "R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %2@"
          "Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D\x06H"
          "\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8\x00)"
          "\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19 %"
          "2@Jd\x80\x94\xC8\x00)\x91\x01R\"\x03\xA4""D"
          "\x06H\x89\f\x90\x12\x19 %2@Jd\x80\x94\xC8"
          "\x00)\x91\x01R\"\x03\xA4""D\x06H\x89\f\x90\x12\x19" // and even more
          

          I believe it might have something to do with the way I am chunking the bytearray? But QT Creator is showing each part as it is from the original array without any events of x00 missing.

          QByteArray s3 = s1;
              int chunkSize = 16;
              int chunkStart = 0;
              int tempSize = s3.size();
              qInfo() << "BREAK BASE";
              while (tempSize > 0){
                  QByteArray Temp = s3.mid(chunkStart, chunkSize);
                  qInfo() << Temp;
                  tempSize = tempSize - chunkSize;
                  chunkStart += chunkSize;
                  socket.writeDatagram(Temp.data(), QHostAddress("127.0.0.1"), 80); // fill QHostAddress with the board's ethernet address
          

          Maybe I should attempt to use the TCP functions instead...? My previous assignments were done in UDP with much smaller payloads.

          B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #4

          @rsison said in QImage into QByteArray - Can anyone tell me if what it has created is valid enough to be turned back into a PNG?:

          socket.writeDatagram(Temp.data(), QHostAddress("127.0.0.1"), 80);

          Here should be the problematic code I think, why are you using Temp.data() instead of Temp?
          It will get a const char * from Temp and convert it to another QByteArray as a \0 terminated string so there won't be any 0x00 left (and the data after 0x00 in every chunk).
          So you either use writeDatagram(Temp, ... or writeDatagram(Temp.data(), Temp.size(), ...
          Also I think it should be better to use TCP in your case. UDP chunks may arrive in unexpected order, or missing. It is not 100% reliable even transferring on localhost.

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved