Reputation: 1247
I need to convert the QByteArray of a QImage into unsigned char *.
I do it by:
QByteArray data;
QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly);
convImage.save(&buffer, "PNG");
buffer.close()
unsigned char *data_image = (unsigned char *)malloc(data.size());
memcpy(data_image, reinterpret_cast<unsigned char *>(data.data()), (unsigned int)data.size());
But the result of data_image compared to the QByteArray of the image is like this:
data = (QByteArray of the Image)
data_image = unsigned char* from data
I think it's not fully copied. I need the unsigned char* data for an external DLL function.
Upvotes: 0
Views: 1130
Reputation: 809
If you have QImage, you can do it simpler:
unsigned char *data_image = (unsigned char *)malloc(convImage.sizeInBytes());
memcpy(data_image, convImage.bits(), convImage.sizeInBytes());
Upvotes: 1
Reputation: 8311
You do not see the full length of the data_image
array, because it is just a pointer and there is no way to know what its actual size is.
So the debugger is applying some standard rules to stop when it thinks it should. On such rule is to stop on a NULL byte.
If you are using Qt Creator, there are several ways you can force the debugger to show more data:
Change Value Display Format > Array of xxx items
. This is the easiest way, but it is limited as you can only select 10, 100, 1,000 or 10,000 items.Open Memory Editor > Open Memory View At Object Address
. This is the most versatile as you can see everything in memory, but it might be more confusing if you are not used to play with memory views.Upvotes: 1