How do I convert QImage in Format_ARGB32 data to a pointer unsigned int*?
-
I want to convert a QImage of format RGB888 to ARGB32 & fetch pixel data as unsigned int*.
I can do the following to convert to ARGB32
@QImage new = old.convertToFormat(QImage::Format_ARGB32);@
However, are the pixels stored signed or unsigned?
I need a pointer unsigned int* data, such that,
an unsigned int (32 bits) holds a pixel in ARGB format, which from left to right is as follows:
- the first 8 bits are for the alpha channel (and are ignored)
- the next 8 bits are for the red channel
- the next 8 bits are for the green channel
- the last 8 bits are for the blue channel
How do I do this?
-
Hi,
@quint32 argbPtr = reinterpret_cast<quint32>(newImage.bits())@
And you should be good to go.
EDIT: corrected cast type, sorry for the error
-
Then I will need to convert from quint32* to uint* or unsigned int*. How will I do that?
[quote author="SGaist" date="1381869224"]Hi,@quint32 argbPtr = static_cast<quint32>(newImage.bits())@
And you should be good to go.[/quote]
-
You should avoid using an int in this case, since you want it to be explicitly 32 bits. quint32 is exactly what you want and will be platform/compiler independent.
-
Umm.... 1st of all, doing
quint32 argbPtr = static_cast<quint32>(newImage.bits())
gives me an error.Secondly, I need to get uint*, since I have to pass it through another function belonging to some other library.
[quote author="Timothy" date="1382019170"]You should avoid using an int in this case, since you want it to be explicitly 32 bits. quint32 is exactly what you want and will be platform/compiler independent.[/quote]
-
bq. quint32 argbPtr = static_cast<quint32>(newImage.bits())
you forgot the *'s :-) -
I still get an error:
error: invalid static_cast from type 'uchar*' to type 'quint32*'
[quote author="Timothy" date="1382020222"]bq. quint32 argbPtr = static_cast<quint32>(newImage.bits())
you forgot the *'s :-)
[/quote] -
@uint bits = reinterpret_cast<uint>(image.bits());@
or
@uint bits = (uint)image.bits();@
and check the sizeof(uint) to be sure is 4