qt图片从16进制转化为bytearray有乱码
时间: 2024-04-30 12:18:17 浏览: 92
CRC16的demo程序-QString类型16进制转换为ByteArray-每两位数据增加空格
可能是因为你的16进制字符串并不是有效的图片数据,或者你在转换过程中出现了一些错误。以下是一个将16进制字符串转换为QByteArray并显示为图片的示例代码:
```cpp
QString hexString = "FFD8FFE000104A46494600010100004800480000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832211C2132323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323FFC00011080001000103012200021101031101FFDD0004001E0102030405060708090A0B0C0D0E0F1011FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF0F1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0B0C0D0E0F1011FFC400B5110002010204040304070504040001027700010203110405213106124171711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00E0E0F7A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0AFFC40014100100000000000000000000000000000000FFC40014110100000000000000000000000000000000FFDA0008010100013F10"
QByteArray imageData;
QByteArray hexData = QByteArray::fromHex(hexString.toUtf8());
imageData.append(hexData);
QPixmap pixmap;
pixmap.loadFromData(imageData);
QLabel label;
label.setPixmap(pixmap);
label.show();
```
请注意,这只是一个简单的示例代码,实际上你需要根据你的具体情况进行调整。如果问题仍然存在,你可能需要进一步检查你的数据和代码。
阅读全文