Qbytearray printing out the values between 0 and 255
-
Hi guys,
I've 2 images drawn upon each other, now when I put the image in a Qbytearray and then ask the .data then I normally get values between 0 and 255 right? Now I get those values but some of them are negative.
Is this normal or is it because there are 2 images on each other that the negative ones are from the foreground image and the other from the background?
@ QImage myImage;
QImage myImage2;
myImage2.load("Mountain-icon");
myImage.load("clouds.jpg");
myImage2 = myImage2.convertToFormat(QImage::Format_ARGB32);
myImage = myImage.convertToFormat(QImage::Format_ARGB32);for(int i = 0; i < 100; i++) for(int y = 0; y < 100; y++) myImage.setPixel(i,y,qRgba(0, 0, 0, 0)); QPainter painter(&myImage); for (int i=0; i<100; i++) { for (int j=0; j<100; j++) { double hue = (double)(i + j + i*j)/361200.0; QColor myColor; myColor.setHsvF(hue, 1.0, 1.0, 1.0); painter.setPen(myColor); painter.drawPoint(i, j); } } painter.drawImage(0,0,myImage2); QLabel myLabel2; myLabel2.setPixmap(QPixmap::fromImage(myImage)); myLabel2.show(); QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); myImage.save(&buffer, "JPEG"); // writes image into ba in PNG format for(int i = 0; i < ba.size(); ++i) cout << (int)ba.at(i) << endl;
@
kind regards,
-
Hi,
@
char QByteArray::at ( int i ) const
@returns signed char. Its values are between -128 and 127. So it is normal.
-
the method is returning a "char value":http://developer.qt.nokia.com/doc/qt-4.8/qbytearray.html#at
The interpretation of char is dependent on the compiler/OS you are using. I have run into a similar problem with char. msvc 2005 interpret it in the range of 0 and 255 (basically unsigned) and linux/gcc was interpreting as signed char.
You need to check the interpretation of char of your compiler and the settings.You may use also "operator[]":http://developer.qt.nokia.com/doc/qt-4.8/qbytearray.html#operator-5b-5d and QByteRef. Check this if it works.
-
Hi,
Thanks for your help. Is it possible to make an Qbytearray from 2 images that sets a 1 if it is the background image and a 0 if it is the foreground image? Because I'm searching all over the internet for this, but I don't find how to do this..Kind regards,
-
I am not sure if you really want to go through a qbytearray. You can manipulate the images directly as it was suggested in "your other post":http://developer.qt.nokia.com/forums/viewthread/14323/