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. Qbytearray printing out the values between 0 and 255
Forum Updated to NodeBB v4.3 + New Features

Qbytearray printing out the values between 0 and 255

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.6k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    browser90
    wrote on last edited by
    #1

    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,

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      Hi,

      @
      char QByteArray::at ( int i ) const
      @

      returns signed char. Its values are between -128 and 127. So it is normal.

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        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.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • B Offline
          B Offline
          browser90
          wrote on last edited by
          #4

          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,

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            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/

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0

            • Login

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